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

            // Recompute the diffuse/alpha material color parameter?
            if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0)
            {
                diffuseColorParam.SetValue(new Vector4(diffuseColor * alpha, alpha));

                dirtyFlags &= ~EffectDirtyFlags.MaterialColor;
            }

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

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

                if (vertexColorEnabled)
                {
                    shaderIndex += 2;
                }

                shaderIndexParam.SetValue(shaderIndex);

                dirtyFlags &= ~EffectDirtyFlags.ShaderIndex;
            }
        }
コード例 #2
0
ファイル: AlphaTestEffect.cs プロジェクト: zfigura/FNA
        /// <summary>
        /// Lazily computes derived parameter values immediately before applying the effect.
        /// </summary>
        protected internal override void OnApply()
        {
            // Recompute the world+view+projection matrix or fog vector?
            dirtyFlags = EffectHelpers.SetWorldViewProjAndFog(dirtyFlags, ref world, ref view, ref projection, ref worldView, fogEnabled, fogStart, fogEnd, worldViewProjParam, fogVectorParam);

            // Recompute the diffuse/alpha material color parameter?
            if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0)
            {
                diffuseColorParam.SetValue(new Vector4(diffuseColor * alpha, alpha));

                dirtyFlags &= ~EffectDirtyFlags.MaterialColor;
            }

            // Recompute the alpha test settings?
            if ((dirtyFlags & EffectDirtyFlags.AlphaTest) != 0)
            {
                Vector4 alphaTest = new Vector4();
                bool    eqNe      = false;

                // Convert reference alpha from 8 bit integer to 0-1 float format.
                float reference = (float)referenceAlpha / 255f;

                // Comparison tolerance of half the 8 bit integer precision.
                const float threshold = 0.5f / 255f;

                switch (alphaFunction)
                {
                case CompareFunction.Less:
                    // Shader will evaluate: clip((a < x) ? z : w)
                    alphaTest.X = reference - threshold;
                    alphaTest.Z = 1;
                    alphaTest.W = -1;
                    break;

                case CompareFunction.LessEqual:
                    // Shader will evaluate: clip((a < x) ? z : w)
                    alphaTest.X = reference + threshold;
                    alphaTest.Z = 1;
                    alphaTest.W = -1;
                    break;

                case CompareFunction.GreaterEqual:
                    // Shader will evaluate: clip((a < x) ? z : w)
                    alphaTest.X = reference - threshold;
                    alphaTest.Z = -1;
                    alphaTest.W = 1;
                    break;

                case CompareFunction.Greater:
                    // Shader will evaluate: clip((a < x) ? z : w)
                    alphaTest.X = reference + threshold;
                    alphaTest.Z = -1;
                    alphaTest.W = 1;
                    break;

                case CompareFunction.Equal:
                    // Shader will evaluate: clip((abs(a - x) < Y) ? z : w)
                    alphaTest.X = reference;
                    alphaTest.Y = threshold;
                    alphaTest.Z = 1;
                    alphaTest.W = -1;
                    eqNe        = true;
                    break;

                case CompareFunction.NotEqual:
                    // Shader will evaluate: clip((abs(a - x) < Y) ? z : w)
                    alphaTest.X = reference;
                    alphaTest.Y = threshold;
                    alphaTest.Z = -1;
                    alphaTest.W = 1;
                    eqNe        = true;
                    break;

                case CompareFunction.Never:
                    // Shader will evaluate: clip((a < x) ? z : w)
                    alphaTest.Z = -1;
                    alphaTest.W = -1;
                    break;

                case CompareFunction.Always:
                default:
                    // Shader will evaluate: clip((a < x) ? z : w)
                    alphaTest.Z = 1;
                    alphaTest.W = 1;
                    break;
                }

                alphaTestParam.SetValue(alphaTest);

                dirtyFlags &= ~EffectDirtyFlags.AlphaTest;

                // If we changed between less/greater vs. equal/notequal
                // compare modes, we must also update the shader index.
                if (isEqNe != eqNe)
                {
                    isEqNe      = eqNe;
                    dirtyFlags |= EffectDirtyFlags.ShaderIndex;
                }
            }

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

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

                if (vertexColorEnabled)
                {
                    shaderIndex += 2;
                }

                if (isEqNe)
                {
                    shaderIndex += 4;
                }

                shaderIndexParam.SetValue(shaderIndex);

                dirtyFlags &= ~EffectDirtyFlags.ShaderIndex;
            }
        }
コード例 #3
0
ファイル: BasicEffect.cs プロジェクト: oeoen/SharpDX
        /// <summary>
        /// Lazily computes derived parameter values immediately before applying the effect.
        /// </summary>
        protected internal override EffectPass OnApply(EffectPass pass)
        {
            // Make sure that domain, hull and geometry shaders are disable.
            GraphicsDevice.DomainShaderStage.Set(null);
            GraphicsDevice.HullShaderStage.Set(null);
            GraphicsDevice.GeometryShaderStage.Set(null);

            // Recompute the world+view+projection matrix or fog vector?
            dirtyFlags = EffectHelpers.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 & EffectDirtyFlags.MaterialColor) != 0)
            {
                EffectHelpers.SetMaterialColor(lightingEnabled, alpha, ref diffuseColor, ref emissiveColor, ref ambientLightColor, diffuseColorParam, emissiveColorParam);

                dirtyFlags &= ~EffectDirtyFlags.MaterialColor;
            }

            if (lightingEnabled)
            {
                // Recompute the world inverse transpose and eye position?
                dirtyFlags = EffectHelpers.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 |= EffectDirtyFlags.ShaderIndex;
                }
            }

            // Recompute the shader index?
            if ((dirtyFlags & EffectDirtyFlags.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;
                    }
                }

                shaderPass = pass.SubPasses[shaderIndex];

                dirtyFlags &= ~EffectDirtyFlags.ShaderIndex;
            }

            // Call the base class to process callbacks
            pass = base.OnApply(shaderPass);

            return(pass);
        }
コード例 #4
0
ファイル: BasicEffect.cs プロジェクト: oeoen/SharpDX
        ///// <summary>
        ///// Creates a new BasicEffect by cloning parameter settings from an existing instance.
        ///// </summary>
        //protected BasicEffect(BasicEffect 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;
        //}


        /// <summary>
        /// Creates a clone of the current BasicEffect instance.
        /// </summary>
        //public override Effect Clone()
        //{
        //    return new BasicEffect(this);
        //}

        /// <summary>
        /// Sets up the standard key/fill/back lighting rig.
        /// </summary>
        public void EnableDefaultLighting()
        {
            LightingEnabled = true;

            AmbientLightColor = EffectHelpers.EnableDefaultLighting(light0, light1, light2);
        }
コード例 #5
0
        /// <summary>
        /// Lazily computes derived parameter values immediately before applying the effect.
        /// </summary>
        protected internal override void OnApply()
        {
            // Recompute the world+view+projection matrix or fog vector?
            dirtyFlags = EffectHelpers.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 & EffectDirtyFlags.MaterialColor) != 0)
            {
                EffectHelpers.SetMaterialColor(lightingEnabled, alpha, ref diffuseColor, ref emissiveColor, ref ambientLightColor, diffuseColorParam, emissiveColorParam);

                dirtyFlags &= ~EffectDirtyFlags.MaterialColor;
            }

            if (lightingEnabled)
            {
                // Recompute the world inverse transpose and eye position?
                dirtyFlags = EffectHelpers.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 |= EffectDirtyFlags.ShaderIndex;
                }
            }

            // Recompute the shader index?
            if ((dirtyFlags & EffectDirtyFlags.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;
                    }
                }

                shaderIndexParam.SetValue(shaderIndex);

                dirtyFlags &= ~EffectDirtyFlags.ShaderIndex;
            }
        }
コード例 #6
0
 public IList <string> Scroll(string content, int lines, int delay, int step = 1) => EffectHelpers.Scroll(ScriptRoot, content, lines, delay, step);