11#pass SHADOW_PASS
22
33#feature PARALLAX_MAPPING
4- #feature ALPHA_CLIPPING
5- #feature ALPHA_DITHERING
64#feature NORMAL_MAPPING
75#feature DISTANCE_FADE
86#feature SPECULAR_WORKFLOW
9- #feature GAMMA_CORRECTION
107
118#shader vertex
129#version 450 core
@@ -96,10 +93,6 @@ uniform int u_MinLayers = 8;
9693uniform int u_MaxLayers = 64;
9794#endif
9895
99- #if defined(ALPHA_CLIPPING)
100- uniform float u_AlphaClippingThreshold = 0.1;
101- #endif
102-
10396#if defined(SHADOW_PASS)
10497#undef PARALLAX_MAPPING // Disable parallax mapping in shadow pass
10598uniform float u_ShadowClippingThreshold = 0.5;
@@ -113,6 +106,13 @@ uniform float u_DistanceFadeLength = 10.0;
113106uniform vec2 u_TextureTiling = vec2(1.0, 1.0);
114107uniform vec2 u_TextureOffset = vec2(0.0, 0.0);
115108
109+ uniform float u_AlphaClippingThreshold = 0.0;
110+ uniform bool u_AlphaDithering = false;
111+
112+ // Useful when no post-processing is applied.
113+ uniform bool u_BuiltInToneMapping = false;
114+ uniform bool u_BuiltInGammaCorrection = false;
115+
116116uniform sampler2D _ShadowMap;
117117uniform mat4 _LightSpaceMatrix;
118118
@@ -149,20 +149,15 @@ void main()
149149 }
150150#else
151151
152- #if defined(ALPHA_CLIPPING)
153152 if (albedo.a < u_AlphaClippingThreshold)
154153 {
155154 discard;
156155 }
157- #endif
158156
159- #if defined(ALPHA_DITHERING)
160- const float ditheredAlpha = Dithering(albedo.a, gl_FragCoord.xy);
161- if (ditheredAlpha < 0)
157+ if (u_AlphaDithering && Dithering(albedo.a, gl_FragCoord.xy) < 0)
162158 {
163159 discard;
164160 }
165- #endif
166161
167162#if defined(NORMAL_MAPPING)
168163 const vec3 normal = ComputeNormal(texCoords, fs_in.Normal, u_NormalMap, fs_in.TBN);
@@ -194,9 +189,11 @@ void main()
194189 _LightSpaceMatrix
195190 );
196191
197- #if defined(GAMMA_CORRECTION)
198- pbr = pow(pbr, vec3(1.0 / 2.2));
199- #endif
192+ // Simple built-in tonemapping (Reinhard) and gamma correction for elements
193+ // not affected by post-processing (e.g. debug, UI, etc.), but still aiming
194+ // to approximate the final PBR look.
195+ pbr = mix(pbr, pbr / (pbr + vec3(1.0)), u_BuiltInToneMapping);
196+ pbr = mix(pbr, pow(pbr, vec3(1.0 / 2.2)), u_BuiltInGammaCorrection);
200197
201198 FRAGMENT_COLOR = vec4(pbr, albedo.a);
202199#endif
0 commit comments