Procházet zdrojové kódy

Add depth clamping support

Popov72 před 5 roky
rodič
revize
cbdaf3b01c

+ 9 - 0
src/Shaders/shadowMap.fragment.fx

@@ -12,6 +12,10 @@ uniform sampler2D diffuseSampler;
 uniform vec3 biasAndScale;
 uniform vec2 depthValues;
 
+#ifdef DEPTHCLAMP
+varying float z;
+#endif
+
 void main(void)
 {
 #ifdef ALPHATEST
@@ -21,6 +25,11 @@ void main(void)
 
     float depth = vDepthMetric;
 
+#ifdef DEPTHCLAMP
+    depth = clamp(((z + depthValues.x) / (depthValues.y)) + biasAndScale.x, 0.0, 1.0);
+    gl_FragDepth = depth;
+#endif
+
 #ifdef ESM
     depth = clamp(exp(-min(87., biasAndScale.z * depth)), 0., 1.);
 #endif

+ 9 - 0
src/Shaders/shadowMap.vertex.fx

@@ -32,6 +32,10 @@ attribute vec2 uv2;
 #endif
 #endif
 
+#ifdef DEPTHCLAMP
+varying float z;
+#endif
+
 void main(void)
 {
 vec3 positionUpdated = position;
@@ -78,8 +82,13 @@ gl_Position = viewProjection * worldPos;
     gl_Position.z += biasAndScale.x * gl_Position.w;
 #endif
 
+#ifdef DEPTHCLAMP
+    z = gl_Position.z;
+    gl_Position.z = 0.0;
+#else
     // Color Texture Linear bias.
     vDepthMetric = ((gl_Position.z + depthValues.x) / (depthValues.y)) + biasAndScale.x;
+#endif
 
 #ifdef ALPHATEST
     #ifdef UV1