File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
src/engine/renderer/glsl_source Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ IN(smooth) vec2 var_TexCoords;
35
35
IN(smooth ) vec4 var_Color;
36
36
37
37
#if defined(USE_DEPTH_FADE)
38
- IN(smooth ) vec2 var_FadeDepth;
38
+ IN(smooth ) float var_FadeDepth;
39
39
uniform sampler2D u_DepthMap;
40
40
#endif
41
41
@@ -55,7 +55,14 @@ void main()
55
55
56
56
#if defined(USE_DEPTH_FADE)
57
57
float depth = texture2D (u_DepthMap, gl_FragCoord .xy / r_FBufSize).x;
58
- float fadeDepth = 0.5 * var_FadeDepth.x / var_FadeDepth.y + 0.5 ;
58
+
59
+ // convert z from normalized device coordinates [-1, 1]
60
+ // to window coordinates [0, 1]
61
+ float fadeDepth = 0.5 * var_FadeDepth + 0.5 ;
62
+
63
+ // HACK: the (distance from triangle to object behind it) / (shader's depthFade distance) ratio
64
+ // is calculated by using (nonlinear) depth values instead of the correct world units, so the
65
+ // fade curve will be different depending on the distance to the viewer and znear/zfar
59
66
color.a *= smoothstep (gl_FragCoord .z, fadeDepth, depth);
60
67
#endif
61
68
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ uniform mat4 u_ModelViewProjectionMatrix;
40
40
41
41
#if defined(USE_DEPTH_FADE)
42
42
uniform float u_DepthScale;
43
- OUT(smooth ) vec2 var_FadeDepth;
43
+ OUT(smooth ) float var_FadeDepth;
44
44
#endif
45
45
46
46
OUT(smooth ) vec2 var_TexCoords;
@@ -96,7 +96,7 @@ void main()
96
96
#if defined(USE_DEPTH_FADE)
97
97
// compute z of end of fading effect
98
98
vec4 fadeDepth = u_ModelViewProjectionMatrix * (position - u_DepthScale * vec4 (LB.normal, 0.0 ));
99
- var_FadeDepth = fadeDepth.zw ;
99
+ var_FadeDepth = fadeDepth.z / fadeDepth.w ;
100
100
#endif
101
101
102
102
var_Color = color;
You can’t perform that action at this time.
0 commit comments