示例#1
0
文件: Scene.cs 项目: bburhans/vtank
        public void ConfigureEffect()
        {
            UniversalEffect effect = RendererAssetPool.UniversalEffect;


            effect.LightParameters.EnableLighting = GraphicOptions.ShadingSupport;
            effect.ShadowParameters.EnableShadows = RendererAssetPool.DrawShadows;

            //Light Parameters
            effect.LightParameters.Position   = worldLight.Position;
            effect.LightParameters.View       = worldLight.View;
            effect.LightParameters.Projection = worldLight.Projection;

            effect.LightParameters.Color = lightColor;

            //Camera Parameters
            effect.CameraParameters.Position   = CurrentCamera.Position;
            effect.CameraParameters.Projection = CurrentCamera.Projection;
            effect.CameraParameters.View       = CurrentCamera.View;

            //World Parameters
            effect.WorldParameters.WorldMatrix = Matrix.Identity;
            if (!GraphicOptions.ShadingSupport)
            {
                AmbientColor = Color.White;
            }
            effect.LightParameters.AmbientColor = AmbientColor;
            if (RendererAssetPool.ParticleEffect != null)
            {
                RendererAssetPool.ParticleEffect.Parameters["xAmbient"].SetValue(AmbientColor.ToVector4());
            }
        }
示例#2
0
        public override void SetEffect(GameTime gameTime, Effect effect)
        {
            base.SetEffect(gameTime, effect);


            if (effect.Parameters["AmbientIntensity"] != null)
            {
                effect.Parameters["AmbientIntensity"].SetValue(AmbientIntensity);
            }

            if (effect.Parameters["AmbientColor"] != null)
            {
                effect.Parameters["AmbientColor"].SetValue(AmbientColor.ToVector4());
            }

            if (effect.Parameters["itw"] != null)
            {
                effect.Parameters["itw"].SetValue(Matrix.Invert(Matrix.Transpose(World)));
            }

            if (MultiLight)
            {
                // Calculate the light direction in relation to me.
                if (effect.Parameters["LightDirection"] != null)
                {
                    effect.Parameters["LightDirection"].SetValue(Lights.Select(p => p.Position - Position).ToArray());
                }

                if (effect.Parameters["DiffuseIntensity"] != null)
                {
                    effect.Parameters["DiffuseIntensity"].SetValue(Lights.Select(p => p.LightIntensity).ToArray());
                }
                if (effect.Parameters["DiffuseColor"] != null)
                {
                    effect.Parameters["DiffuseColor"].SetValue(Lights.Select(p => p.Color.ToVector4()).ToArray());
                }

                if (effect.Parameters["SpecularColor"] != null)
                {
                    effect.Parameters["SpecularColor"].SetValue(Lights.Select(p => p.SpecularColor.ToVector4()).ToArray());
                }
                if (effect.Parameters["SpecularIntensity"] != null)
                {
                    effect.Parameters["SpecularIntensity"].SetValue(Lights.Select(p => p.SpecularIntensity).ToArray());
                }
            }
            else
            {
                if (effect.Parameters["LightDirection"] != null)
                {
                    effect.Parameters["LightDirection"].SetValue(Lights[0].Position - Position);
                }

                if (effect.Parameters["DiffuseIntensity"] != null)
                {
                    effect.Parameters["DiffuseIntensity"].SetValue(Lights[0].LightIntensity);
                }
                if (effect.Parameters["DiffuseColor"] != null)
                {
                    effect.Parameters["DiffuseColor"].SetValue(Lights[0].Color.ToVector4());
                }

                if (effect.Parameters["SpecularColor"] != null)
                {
                    effect.Parameters["SpecularColor"].SetValue(Lights[0].SpecularColor.ToVector4());
                }
                if (effect.Parameters["SpecularIntensity"] != null)
                {
                    effect.Parameters["SpecularIntensity"].SetValue(Lights[0].SpecularIntensity);
                }
            }

            if (effect.Parameters["CameraPosition"] != null)
            {
                effect.Parameters["CameraPosition"].SetValue(camera.Position);
            }

            if (effect.Parameters["ColorMap"] != null)
            {
                effect.Parameters["ColorMap"].SetValue(Game.Content.Load <Texture2D>(ColorAsset));
            }
            if (effect.Parameters["GlowMap"] != null)
            {
                effect.Parameters["GlowMap"].SetValue(Game.Content.Load <Texture2D>(GlowAsset));
            }
            if (effect.Parameters["BumpMap"] != null)
            {
                effect.Parameters["BumpMap"].SetValue(Game.Content.Load <Texture2D>(BumpAsset));
            }
            if (effect.Parameters["ReflectionMap"] != null)
            {
                effect.Parameters["ReflectionMap"].SetValue(Game.Content.Load <Texture2D>(ReflectionAsset));
            }

            if (effect.Parameters["worldIT"] != null)
            {
                effect.Parameters["worldIT"].SetValue(Matrix.Invert(Matrix.Transpose(World)));
            }

            if (effect.Parameters["viewI"] != null)
            {
                effect.Parameters["viewI"].SetValue(Matrix.Invert(camera.View));
            }

            if (effect.Parameters["cubeMap"] != null)
            {
                effect.Parameters["cubeMap"].SetValue(Game.Content.Load <TextureCube>(ColorAsset));
            }

            if (effect.Parameters["tint"] != null)
            {
                effect.Parameters["tint"].SetValue(Tint.ToVector4());
            }

            if (effect.Parameters["fresnelTex"] != null)
            {
                effect.Parameters["fresnelTex"].SetValue(Game.Content.Load <Texture2D>(GlowAsset));
            }

            if (effect.Parameters["EyePosition"] != null)
            {
                effect.Parameters["EyePosition"].SetValue(camera.Position);
            }

            if (effect.Parameters["time"] != null)
            {
                effect.Parameters["time"].SetValue((float)gameTime.TotalGameTime.TotalSeconds * 3);
            }


            if (effect.Parameters["CloudMap"] != null)
            {
                effect.Parameters["CloudMap"].SetValue(Game.Content.Load <Texture2D>(CloudMap));
            }

            if (effect.Parameters["WaveMap"] != null)
            {
                effect.Parameters["WaveMap"].SetValue(Game.Content.Load <Texture2D>(WaterRipples));
            }

            if (effect.Parameters["AtmosMap"] != null)
            {
                effect.Parameters["AtmosMap"].SetValue(Game.Content.Load <Texture2D>(AtmosAsset));
            }

            if (effect.Parameters["cloudSpeed"] != null)
            {
                effect.Parameters["cloudSpeed"].SetValue(cloudSpeed);
            }

            if (effect.Parameters["cloudHeight"] != null)
            {
                effect.Parameters["cloudHeight"].SetValue(cloudHeight);
            }

            if (effect.Parameters["cloudShadowIntensity"] != null)
            {
                effect.Parameters["cloudShadowIntensity"].SetValue(cloudShadowIntensity);
            }
        }