/// <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; } } }
private static string CreateProtoPixelShader(ShaderEffectProps effectProps) { var protoPixelShader = new List <string> { HeaderShard.Version300Es, HeaderShard.EsPrecisionHighpFloat, FragPropertiesShard.InParams(effectProps), FragPropertiesShard.FuseeMatrixUniforms(), FragPropertiesShard.MaterialPropsUniforms(effectProps), }; return(string.Join("\n", protoPixelShader)); }
private static string CreateDeferredLightingPixelShader(Light lc, bool isCascaded = false, int numberOfCascades = 0, bool debugCascades = false) { var frag = new StringBuilder(); frag.Append(HeaderShard.Version300Es); frag.Append("#extension GL_ARB_explicit_uniform_location : enable\n"); frag.Append("#extension GL_ARB_gpu_shader5 : enable\n"); frag.Append(HeaderShard.EsPrecisionHighpFloat); frag.Append(FragPropertiesShard.DeferredTextureUniforms()); frag.Append(FragPropertiesShard.FuseeMatrixUniforms()); frag.Append(LightingShard.LightStructDeclaration); frag.Append(FragPropertiesShard.DeferredLightAndShadowUniforms(lc, isCascaded, numberOfCascades)); frag.Append(GLSL.CreateIn(GLSL.Type.Vec2, VaryingNameDeclarations.TextureCoordinates)); frag.Append(FragPropertiesShard.ColorOut()); //Shadow calculation methods //-------------------------------------- if (lc.Type != LightType.Point) { frag.Append(LightingShard.ShadowCalculation()); } else { frag.Append(LightingShard.ShadowCalculationCubeMap()); } //Lighting methods //------------------------------------------ frag.Append(LightingShard.AmbientComponent()); frag.Append(LightingShard.SpecularComponent()); frag.Append(LightingShard.DiffuseComponent()); frag.Append(LightingShard.AttenuationPointComponent()); frag.Append(LightingShard.AttenuationConeComponent()); frag.Append(LightingShard.ApplyLightDeferred(lc, isCascaded, numberOfCascades, debugCascades)); return(frag.ToString()); }
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)); }