Пример #1
0
        /// <summary>
        ///Called by the SceneVisitor in the pre-pass to create the correct fragment shader, whether we render forward or deferred.
        /// </summary>
        public void CreateFragmentShader(bool doRenderForward)
        {
            if (doRenderForward)
            {
                for (int i = 0; i < _effectPasses.Length; i++)
                {
                    var pxBody = new List <string>()
                    {
                        LightingShard.LightStructDeclaration,
                        FragPropertiesShard.FixedNumberLightArray,
                        FragPropertiesShard.ColorOut(),
                        LightingShard.AssembleLightingMethods(EffectProps),
                        FragMainShard.ForwardLighting(EffectProps)
                    };

                    PixelShaderSrc[i] = _effectPasses[i].ProtoPS + string.Join("\n", pxBody);
                }
            }
            else
            {
                for (int i = 0; i < _effectPasses.Length; i++)
                {
                    var pxBody = new List <string>()
                    {
                        FragPropertiesShard.GBufferOut(),
                        FragMainShard.RenderToGBuffer(EffectProps)
                    };
                    PixelShaderSrc[i] = _effectPasses[i].ProtoPS + string.Join("\n", pxBody);

                    States[i].AlphaBlendEnable = false;
                    States[i].ZEnable          = true;
                }
            }
        }
Пример #2
0
        private static string CreatePixelShader(ShaderEffectProps effectProps)
        {
            var pixelShader = new List <string>
            {
                HeaderShard.Version300Es,
                HeaderShard.EsPrecisionHighpFloat,

                LightingShard.LightStructDeclaration,

                FragPropertiesShard.InParams(effectProps),
                FragPropertiesShard.FuseeMatrixUniforms(),
                FragPropertiesShard.MaterialPropsUniforms(effectProps),
                FragPropertiesShard.FixedNumberLightArray,
                FragPropertiesShard.ColorOut(),
                LightingShard.AssembleLightingMethods(effectProps)
            };

            //Calculates the lighting for all lights by using the above method
            pixelShader.Add(FragMainShard.ForwardLighting(effectProps));

            return(string.Join("\n", pixelShader));
        }