Exemple #1
0
        /// <summary>
        /// Looks up shortcut references to our effect parameters.
        /// </summary>
        void CacheEffectParameters(BlBasicEffect cloneSource)
        {
            textureParam               = Parameters["Texture"];
            diffuseColorParam          = Parameters["DiffuseColor"];
            emissiveColorParam         = Parameters["EmissiveColor"];
            specularColorParam         = Parameters["SpecularColor"];
            specularPowerParam         = Parameters["SpecularPower"];
            eyePositionParam           = Parameters["EyePosition"];
            fogColorParam              = Parameters["FogColor"];
            fogVectorParam             = Parameters["FogVector"];
            worldParam                 = Parameters["World"];
            worldInverseTransposeParam = Parameters["WorldInverseTranspose"];
            worldViewProjParam         = Parameters["WorldViewProj"];

            light0 = new DirectionalLight(Parameters["DirLight0Direction"],
                                          Parameters["DirLight0DiffuseColor"],
                                          Parameters["DirLight0SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light0 : null);

            light1 = new DirectionalLight(Parameters["DirLight1Direction"],
                                          Parameters["DirLight1DiffuseColor"],
                                          Parameters["DirLight1SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light1 : null);

            light2 = new DirectionalLight(Parameters["DirLight2Direction"],
                                          Parameters["DirLight2DiffuseColor"],
                                          Parameters["DirLight2SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light2 : null);
        }
Exemple #2
0
        /// <summary>
        /// Creates a new BlBasicEffect by cloning parameter settings from an existing instance.
        /// </summary>
        protected BlBasicEffect(BlBasicEffect cloneSource)
            : base(cloneSource)
        {
            CacheEffectParameters(cloneSource);

            lightingEnabled        = cloneSource.lightingEnabled;
            preferPerPixelLighting = cloneSource.preferPerPixelLighting;
            fogEnabled             = cloneSource.fogEnabled;
            textureEnabled         = cloneSource.textureEnabled;
            vertexColorEnabled     = cloneSource.vertexColorEnabled;

            world      = cloneSource.world;
            view       = cloneSource.view;
            projection = cloneSource.projection;

            diffuseColor      = cloneSource.diffuseColor;
            emissiveColor     = cloneSource.emissiveColor;
            ambientLightColor = cloneSource.ambientLightColor;

            alpha = cloneSource.alpha;

            fogStart = cloneSource.fogStart;
            fogEnd   = cloneSource.fogEnd;
        }
Exemple #3
0
        /// <summary>
        /// Sets up in the specified BlBasicEffect with all matrices and lighting parameters for this sprite.
        /// App code might call this from a SetEffect delegate if, for example, it is using one of the
        /// BlBasicEffectxxx effects, like the BlBasicEffectWithAlphaTest.
        /// </summary>
        public void SetupBasicEffect(BlBasicEffect effect)
        {
            effect.Projection = Graphics.Projection;
            effect.View       = Graphics.View;
            effect.World      = AbsoluteMatrix;

            effect.LightingEnabled = true;
            do
            {
                if (Graphics.Lights.Count < 1)
                {
                    effect.DirectionalLight0.Enabled = false;
                    effect.DirectionalLight1.Enabled = false;
                    effect.DirectionalLight2.Enabled = false;
                    break;
                }

                var light = Graphics.Lights[0];
                if (light.LightDirection != null)
                {
                    effect.DirectionalLight0.DiffuseColor  = light.LightDiffuseColor;
                    effect.DirectionalLight0.SpecularColor = light.LightSpecularColor;
                    effect.DirectionalLight0.Direction     = (Vector3)light.LightDirection;
                    effect.DirectionalLight0.Enabled       = true;
                }
                else
                {
                    effect.DirectionalLight0.Enabled = false;
                }

                if (Graphics.Lights.Count < 2)
                {
                    effect.DirectionalLight1.Enabled = false;
                    effect.DirectionalLight2.Enabled = false;
                    break;
                }

                light = Graphics.Lights[1];
                if (light.LightDirection != null)
                {
                    effect.DirectionalLight1.DiffuseColor  = light.LightDiffuseColor;
                    effect.DirectionalLight1.SpecularColor = light.LightSpecularColor;
                    effect.DirectionalLight1.Direction     = (Vector3)light.LightDirection;
                    effect.DirectionalLight1.Enabled       = true;
                }
                else
                {
                    effect.DirectionalLight1.Enabled = false;
                }

                if (Graphics.Lights.Count < 3)
                {
                    effect.DirectionalLight2.Enabled = false;
                    break;
                }

                light = Graphics.Lights[2];
                if (light.LightDirection != null)
                {
                    effect.DirectionalLight2.DiffuseColor  = light.LightDiffuseColor;
                    effect.DirectionalLight2.SpecularColor = light.LightSpecularColor;
                    effect.DirectionalLight2.Direction     = (Vector3)light.LightDirection;
                    effect.DirectionalLight2.Enabled       = true;
                }
                else
                {
                    effect.DirectionalLight2.Enabled = false;
                }
            }while (false);

            if (Color != null)
            {
                effect.DiffuseColor = (Vector3)Color;
            }

            if (EmissiveColor != null)
            {
                effect.EmissiveColor = (Vector3)EmissiveColor;
            }

            if (Graphics.AmbientLightColor != null)
            {
                effect.AmbientLightColor = (Vector3)Graphics.AmbientLightColor;
            }

            if (SpecularColor != null)
            {
                effect.SpecularColor = (Vector3)SpecularColor;
                effect.SpecularPower = SpecularPower;
            }

            if (Graphics.FogColor != null)
            {
                effect.FogColor   = (Vector3)Graphics.FogColor;
                effect.FogEnabled = true;
                effect.FogStart   = Graphics.fogStart;
                effect.FogEnd     = Graphics.fogEnd;
            }

            var Texture = GetCurrentTexture();

            if (Texture != null)
            {
                effect.TextureEnabled = true;
                effect.Texture        = Texture;
            }
        }