Exemple #1
0
        /// <summary>
        /// Lazily computes derived parameter values immediately before applying the effect.
        /// </summary>
        protected override void OnApply()
        {
            // Recompute the world+view+projection matrix or fog vector?
            dirtyFlags = BlEffectHelpers.SetWorldViewProjAndFog(dirtyFlags, ref world, ref view, ref projection, ref worldView, fogEnabled, fogStart, fogEnd, worldViewProjParam, fogVectorParam);

            // Recompute the diffuse/emissive/alpha material color parameters?
            if ((dirtyFlags & BlEffectDirtyFlags.MaterialColor) != 0)
            {
                BlEffectHelpers.SetMaterialColor(lightingEnabled, alpha, ref diffuseColor, ref emissiveColor, ref ambientLightColor, diffuseColorParam, emissiveColorParam);

                dirtyFlags &= ~BlEffectDirtyFlags.MaterialColor;
            }

            if (lightingEnabled)
            {
                // Recompute the world inverse transpose and eye position?
                dirtyFlags = BlEffectHelpers.SetLightingMatrices(dirtyFlags, ref world, ref view, worldParam, worldInverseTransposeParam, eyePositionParam);


                // Check if we can use the only-bother-with-the-first-light shader optimization.
                bool newOneLight = !light1.Enabled && !light2.Enabled;

                if (oneLight != newOneLight)
                {
                    oneLight    = newOneLight;
                    dirtyFlags |= BlEffectDirtyFlags.ShaderIndex;
                }
            }

            // Recompute the shader index?
            if ((dirtyFlags & BlEffectDirtyFlags.ShaderIndex) != 0)
            {
                int shaderIndex = 0;

                if (!fogEnabled)
                {
                    shaderIndex += 1;
                }

                if (vertexColorEnabled)
                {
                    shaderIndex += 2;
                }

                if (textureEnabled)
                {
                    shaderIndex += 4;
                }

                if (lightingEnabled)
                {
                    if (preferPerPixelLighting)
                    {
                        shaderIndex += 24;
                    }
                    else if (oneLight)
                    {
                        shaderIndex += 16;
                    }
                    else
                    {
                        shaderIndex += 8;
                    }
                }

                dirtyFlags &= ~BlEffectDirtyFlags.ShaderIndex;

                CurrentTechnique = Techniques[shaderIndex];
            }
        }
Exemple #2
0
        /// <inheritdoc/>
        public void EnableDefaultLighting()
        {
            LightingEnabled = true;

            AmbientLightColor = BlEffectHelpers.EnableDefaultLighting(light0, light1, light2);
        }