Esempio n. 1
0
 static EffectHandles()
 {
     foreach (FieldInfo field in typeof(EffectHandles).GetFields())
     {
         if (field.IsStatic && field.FieldType == typeof(EffectHandle))
         {
             field.SetValue(null, EffectHandle.FromString(field.Name));
         }
     }
 }
Esempio n. 2
0
        public void SetShaderTexture(int stage, BaseTexture texture)
        {
            if (shaderEnabled && effect != null)
            {
                EffectHandle handle = stage == 0 ?
                                      EffectHandle.FromString("tex") :
                                      EffectHandle.FromString("lightmap");

                effect.SetValue(handle, texture);
            }
        }
Esempio n. 3
0
        public void SetVariable(string variableName, ShaderParameters parameter)
        {
            EffectHandle effectHandle = EffectHandle.FromString(variableName);

            if (variables.ContainsKey(effectHandle))
            {
                variables[effectHandle] = parameter;
            }
            else
            {
                variables.Add(effectHandle, parameter);
            }
        }
Esempio n. 4
0
        public void Update(float delta)
        {
            time += delta;

            input.Poll();
            fpsCamera.Update(delta);

            if (!visibilityFixed)
            {
                numVisibleFaces = map.FindVisibleFaces(fpsCamera, visibleFaces);
                QSortFaces(0, numVisibleFaces - 1);
            }

            if (shaderEnabled && effect != null)
            {
                effect.SetValue(EffectHandle.FromString("Time"), time);
            }
        }
        private void setupShaders()
        {
            logMessageToFile("Setup shaders");
            // Load and initialize shader effect
            if (d3dDevice == null)
            {
                return;
            }

            try
            {
                string error = "";
                if (shaderMode == 0)
                {
                    shader = Effect.FromFile(d3dDevice, Path.Combine(Application.StartupPath, "BodyShader.fx"), null, ShaderFlags.None, null, out error);
                }
                if (shaderMode == 1)
                {
                    shader = Effect.FromFile(d3dDevice, Path.Combine(Application.StartupPath, "FaceShader.fx"), null, ShaderFlags.None, null, out error);
                }
                if (shaderMode == 2)
                {
                    shader = Effect.FromFile(d3dDevice, Path.Combine(Application.StartupPath, "HairShader.fx"), null, ShaderFlags.None, null, out error);
                }

                if (shader == null)
                {
                    if (!String.IsNullOrEmpty(error))
                    {
                        MessageBox.Show(error);
                    }
                }
                else
                {
                    shader.SetValue(EffectHandle.FromString("gSkinTexture"), skinTexture);
                    shader.SetValue(EffectHandle.FromString("gSkinSpecular"), skinSpecular);
                    if (models[0].textures.baseTexture != null)
                    {
                        shader.SetValue(EffectHandle.FromString("gMultiplyTexture"), models[0].textures.baseTexture);
                    }
                    shader.SetValue(EffectHandle.FromString("gStencilTexture"), models[0].textures.curStencil);
                    if (models[0].textures.curStencil != null)
                    {
                        shader.SetValue(EffectHandle.FromString("gUseStencil"), true);
                    }
                    shader.SetValue(EffectHandle.FromString("gSpecularTexture"), models[0].textures.specularTexture);
                    if (shaderMode == 0)
                    {
                        //currently only the bodyshader supports bumpmaps
                        shader.SetValue(EffectHandle.FromString("gReliefTexture"), normalMapTexture);
                        if (normalMapTexture != null)
                        {
                            shader.SetValue(EffectHandle.FromString("gUseBumpMap"), true);
                        }

                        shader.SetValue(EffectHandle.FromString("gHideSkin"), hideSkin);
                    }
                    shader.SetValue(EffectHandle.FromString("gTileCount"), 1.0f);
                    shader.SetValue(EffectHandle.FromString("gAmbiColor"), new ColorValue(0.6f, 0.6f, 0.6f));
                    shader.SetValue(EffectHandle.FromString("gLamp0Pos"), new Vector4(-10f, 10f, -10f, 1.0f));
                    shader.SetValue(EffectHandle.FromString("gPhongExp"), 10.0f);
                    shader.SetValue(EffectHandle.FromString("gPhongExp"), 10.0f);
                    shader.SetValue(EffectHandle.FromString("gSpecColor"), new ColorValue(0.2f, 0.2f, 0.2f));
                    shader.SetValue(EffectHandle.FromString("gSurfaceColor"), new ColorValue(0.5f, 0.5f, 0.5f));
                    shader.Technique = shader.GetTechnique("normal_mapping");
                }
                wireframe = Effect.FromFile(d3dDevice, Path.Combine(Application.StartupPath, "Wireframe.fx"), null, ShaderFlags.None, null, out error);
                wireframe.SetValue(EffectHandle.FromString("gColor"), new ColorValue((int)wireframeColour.R, (int)wireframeColour.G, (int)wireframeColour.B));
                wireframe.Technique = wireframe.GetTechnique("wireframe");
            }
            catch (Exception ex)
            {
                logMessageToFile(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Esempio n. 6
0
        private void DrawQ3Map()
        {
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, bgColor, 1.0f, 0);
            ResetDeviceState();

            d3dDevice.SetTransform(TransformType.World, Matrix.Identity);
            d3dDevice.SetTransform(TransformType.View, fpsCamera.ViewMatrix);
            d3dDevice.SetTransform(TransformType.Projection, fpsCamera.ProjMatrix);

            int faceIndex = 0;

            ReadOnlyCollection <Q3BspFace> faces = map.Faces;

            //AutoResetEvent.WaitAll ( bufferLocks );

            if (shaderEnabled && effect != null)
            {
                effect.SetValue(EffectHandle.FromString("worldViewProj"),
                                d3dDevice.Transform.World *
                                d3dDevice.Transform.View *
                                d3dDevice.Transform.Projection);

                effect.SetValue(EffectHandle.FromString("LightEnabled"), lightEnabled);

                if (lightEnabled)
                {
                    effect.SetValue(EffectHandle.FromString("LightPos"), lightPos);
                    effect.SetValue(EffectHandle.FromString("EyePos"),
                                    new Vector4(fpsCamera.Position.X, fpsCamera.Position.Y, fpsCamera.Position.Z, 1.0f));
                }

                effect.SetValue(EffectHandle.FromString("LightmapsEnabled"),
                                (texturingFlags & TexturingFlags.Lightmaps) == TexturingFlags.Lightmaps);
            }

            while (visibleFaces [faceIndex] != -1)
            {
                if (shaderEnabled && effect != null)
                {
                    int numPasses = effect.Begin(FX.None);

                    for (int i = 0; i < numPasses; i++)
                    {
                        effect.BeginPass(i);
                        DrawFace(visibleFaces [faceIndex]);
                        effect.EndPass();
                    }

                    effect.End();
                }
                else
                {
                    DrawFace(visibleFaces [faceIndex]);
                }

                faceIndex++;
            }

            //foreach ( WaitHandle handle in bufferLocks )
            //	( handle as AutoResetEvent ).Set ();
        }