private static GLShader FragmentShader() { return(GLShader.Create(ShaderType.FragmentShader, () => from f in Shader.Inputs <TerrainFragment> () from u in Shader.Uniforms <Terrain> () from l in Shader.Uniforms <LightingUniforms> () from c in Shader.Uniforms <CascadedShadowUniforms> () let rockColor = FragmentShaders.TextureColor(!u.rockSampler, f.fragTexturePos) let grassColor = FragmentShaders.TextureColor(!u.grassSampler, f.fragTexturePos) let sandColor = FragmentShaders.TextureColor(!u.sandSampler, f.fragTexturePos) let sandBlend = FMath.SmoothStep(2f, 4f, f.height) let flatColor = grassColor.Mix(sandColor, sandBlend) let rockBlend = FMath.SmoothStep(0.8f, 0.9f, f.slope) let terrainColor = rockColor.Mix(flatColor, rockBlend) let diffuseLight = LightingShaders.LightDiffuseIntensity( (!l.directionalLight).direction, (!l.directionalLight).intensity, f.vertexNormal) let ambient = (!l.globalLighting).ambientLightIntensity //let shadow = ShadowShaders.PcfShadowMapFactor (f.fragPositionLightSpace, 0.0015f) //let shadow = ShadowShaders.VarianceShadowMapFactor (new Vec4 (f.vertexPos, 1f)) let shadow = ShadowShaders.CascadedShadowMapFactor(new Vec4(f.vertexPos, 1f), 0.0015f) let litColor = LightingShaders.GlobalLightIntensity(!l.globalLighting, ambient, diffuseLight * shadow, new Vec3(0f), terrainColor, new Vec3(0f)) select new { outputColor = litColor.Mix(!u.skyColor, f.visibility) })); }
private static GLShader FragmentShader() { return(GLShader.Create ( ShaderType.FragmentShader, () => from f in Shader.Inputs <EntityFragment> () from u in Shader.Uniforms <Entities> () from l in Shader.Uniforms <LightingUniforms> () from c in Shader.Uniforms <CascadedShadowUniforms> () let samplerNo = (f.fragTexturePos.X / 10f).Truncate() let fragDiffuse = samplerNo == 0 ? FragmentShaders.TextureColor((!u.samplers)[0], f.fragTexturePos) : samplerNo == 1 ? FragmentShaders.TextureColor((!u.samplers)[1], f.fragTexturePos - new Vec2(10f)) : samplerNo == 2 ? FragmentShaders.TextureColor((!u.samplers)[2], f.fragTexturePos - new Vec2(20f)) : samplerNo == 3 ? FragmentShaders.TextureColor((!u.samplers)[3], f.fragTexturePos - new Vec2(30f)) : f.fragDiffuse let dirLight = LightingShaders.DirLightIntensity(!l.directionalLight, f.fragPosition, f.fragNormal, f.fragShininess) let totalLight = Control <LightingShaders.DiffuseAndSpecular> .For(0, (!u.pointLights).Length, dirLight, (i, total) => (from pl in (!u.pointLights)[i].ToShader() let plint = LightingShaders.PointLightIntensity(pl, f.fragPosition, f.fragNormal, f.fragShininess) select new LightingShaders.DiffuseAndSpecular(plint.diffuse + total.diffuse, plint.specular + total.specular)) .Evaluate()) let envLight = (!u.diffuseMap).Texture(f.fragNormal)[Coord.x, Coord.y, Coord.z] let ambient = envLight * (!l.globalLighting).ambientLightIntensity let reflectDiffuse = f.fragReflectivity == 0f ? fragDiffuse : fragDiffuse.Mix(LightingShaders.ReflectedColor(!u.diffuseMap, f.fragPosition, f.fragNormal), f.fragReflectivity) //let shadow = ShadowShaders.PcfShadowMapFactor (f.fragPositionLightSpace, 0.0015f) //let shadow = ShadowShaders.VarianceShadowMapFactor (new Vec4 (f.fragPosition, 1f)) let shadow = ShadowShaders.CascadedShadowMapFactor(new Vec4(f.fragPosition, 1f), 0.002f) select new { outputColor = LightingShaders.GlobalLightIntensity(!l.globalLighting, ambient, totalLight.diffuse * shadow, totalLight.specular * shadow, reflectDiffuse, f.fragSpecular) } )); }