@@ -46,9 +46,7 @@ namespace util = celestia::util;
4646
4747namespace
4848{
49- #if GL_ONLY_SHADOWS
5049constexpr const int ShadowSampleKernelWidth = 2 ;
51- #endif
5250
5351const std::filesystem::path ShaderDirectory{ " shaders" };
5452
@@ -116,7 +114,7 @@ void main(void)
116114#ifdef GL_ES
117115constexpr std::string_view VersionHeader = " #version 300 es\n " sv;
118116constexpr std::string_view VersionHeaderGeom = " #version 320 es\n " sv;
119- constexpr std::string_view CommonHeader = " precision highp float;\n " sv;
117+ constexpr std::string_view CommonHeader = " precision highp float;\n precision highp sampler2DShadow; \ n" sv;
120118#else
121119constexpr std::string_view VersionHeader = " #version 330\n " sv;
122120constexpr std::string_view VersionHeaderGeom = " #version 330\n " sv;
@@ -924,11 +922,7 @@ TextureSamplerDeclarations(const ShaderProperties& props)
924922
925923 if (util::is_set (props.texUsage , TexUsage::ShadowMapTexture))
926924 {
927- #if GL_ONLY_SHADOWS
928925 source += DeclareUniform (" shadowMapTex0" , Shader_Sampler2DShadow);
929- #else
930- source += DeclareUniform (" shadowMapTex0" , Shader_Sampler2D);
931- #endif
932926 }
933927
934928 return source;
@@ -1037,42 +1031,24 @@ std::string
10371031CalculateShadow ()
10381032{
10391033 std::string source;
1040- #if GL_ONLY_SHADOWS
10411034 source += R"glsl(
10421035float calculateShadow()
10431036{
10441037 float texelSize = 1.0 / shadowMapSize;
10451038 float s = 0.0;
10461039 float bias = max(0.005 * (1.0 - cosNormalLightDir), 0.0005);
10471040)glsl" sv;
1048- float boxFilterWidth = ( float ) ShadowSampleKernelWidth - 1 .0f ;
1041+ float boxFilterWidth = static_cast < float >( ShadowSampleKernelWidth) - 1 .0f ;
10491042 float firstSample = -boxFilterWidth / 2 .0f ;
10501043 float lastSample = firstSample + boxFilterWidth;
1051- float sampleWeight = 1 .0f / ( float ) (ShadowSampleKernelWidth * ShadowSampleKernelWidth);
1044+ float sampleWeight = 1 .0f / static_cast < float > (ShadowSampleKernelWidth * ShadowSampleKernelWidth);
10521045 source += fmt::format (" for (float y = {:f}; y <= {:f}; y += 1.0)\n " , firstSample, lastSample);
10531046 source += fmt::format (" for (float x = {:f}; x <= {:f}; x += 1.0)\n " , firstSample, lastSample);
1054- source += " s += shadow2D(shadowMapTex0, shadowTexCoord0.xyz + vec3(x * texelSize, y * texelSize, bias)).z;\n " ;
1047+ // Modern GLSL hardware compare: returns single float (PCF result when
1048+ // GL_LINEAR filter + GL_COMPARE_REF_TO_TEXTURE).
1049+ source += " s += texture(shadowMapTex0, shadowTexCoord0.xyz + vec3(x * texelSize, y * texelSize, bias));\n " ;
10551050 source += fmt::format (" return s * {:f};\n " , sampleWeight);
10561051 source += " }\n " ;
1057- #else
1058- source += R"glsl(
1059- float calculateShadow()
1060- {
1061- float texelSize = 1.0 / shadowMapSize;
1062- float s = 0.0;
1063- float bias = max(0.005 * (1.0 - cosNormalLightDir), 0.0005);
1064- for(float x = -1.0; x <= 1.0; x += 1.0)
1065- {
1066- for(float y = -1.0; y <= 1.0; y += 1.0)
1067- {
1068- float pcfDepth = texture(shadowMapTex0, shadowTexCoord0.xy + vec2(x * texelSize, y * texelSize)).r;
1069- s += shadowTexCoord0.z - bias > pcfDepth ? 1.0 : 0.0;
1070- }
1071- }
1072- return 1.0 - s / 9.0;
1073- }
1074- )glsl" sv;
1075- #endif
10761052 return source;
10771053}
10781054
0 commit comments