Пример #1
0
        /// <summary>
        /// Creates the uniforms for the deferred lighting pass for one light.
        /// </summary>
        /// <param name="lc">The light component, needed to decide if we have a Shadow Cube Map or a standard shadow map.</param>
        /// <param name="isCascaded">If cascaded shadow mapping is used, this should be set to true.</param>
        /// <param name="numberOfCascades">If cascaded shadow mapping is used this is the number of cascades.</param>
        public static string DeferredLightAndShadowUniforms(Light lc, bool isCascaded, int numberOfCascades)
        {
            var uniforms = new List <string>
            {
                "uniform Light light;"
            };

            if (!isCascaded)
            {
                if (lc.IsCastingShadows)
                {
                    if (lc.Type != LightType.Point)
                    {
                        uniforms.Add(GLSL.CreateUniform(GLSL.Type.Sampler2D, UniformNameDeclarations.ShadowMap));
                    }
                    else
                    {
                        uniforms.Add(GLSL.CreateUniform(GLSL.Type.SamplerCube, UniformNameDeclarations.ShadowCubeMap));
                    }
                }
                uniforms.Add(GLSL.CreateUniform(GLSL.Type.Mat4, UniformNameDeclarations.LightSpaceMatrix));
            }
            else
            {
                //No implementation for GLSL.CreateArrayUniform yet...
                uniforms.Add($"uniform {GLSL.DecodeType(GLSL.Type.Sampler2D)}[{numberOfCascades}] ShadowMaps;\n");
                uniforms.Add($"uniform {GLSL.DecodeType(GLSL.Type.Vec2)}[{numberOfCascades}] ClipPlanes;\n");
                uniforms.Add($"uniform {GLSL.DecodeType(GLSL.Type.Mat4)}[{numberOfCascades}] LightSpaceMatrices;\n");
            }

            uniforms.Add(GLSL.CreateUniform(GLSL.Type.Int, UniformNameDeclarations.RenderPassNo));
            uniforms.Add(GLSL.CreateUniform(GLSL.Type.Int, UniformNameDeclarations.SsaoOn));

            uniforms.Add(GLSL.CreateUniform(GLSL.Type.Vec4, UniformNameDeclarations.BackgroundColor));
            return(string.Join("\n", uniforms));
        }