File tree 2 files changed +13
-6
lines changed
src/engine/renderer/glsl_source
2 files changed +13
-6
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) || defined(USE_VERTEX_SPRITE)
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) || defined(USE_VERTEX_SPRITE)
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 @@ -42,10 +42,10 @@ uniform mat4 u_ModelMatrix;
42
42
uniform mat4 u_ModelViewProjectionMatrix;
43
43
44
44
#if defined(USE_VERTEX_SPRITE)
45
- OUT(smooth ) vec2 var_FadeDepth;
45
+ OUT(smooth ) float var_FadeDepth;
46
46
#elif defined(USE_DEPTH_FADE)
47
47
uniform float u_DepthScale;
48
- OUT(smooth ) vec2 var_FadeDepth;
48
+ OUT(smooth ) float var_FadeDepth;
49
49
#endif
50
50
51
51
OUT(smooth ) vec2 var_TexCoords;
@@ -101,10 +101,10 @@ void main()
101
101
#if defined(USE_DEPTH_FADE)
102
102
// compute z of end of fading effect
103
103
vec4 fadeDepth = u_ModelViewProjectionMatrix * (position - u_DepthScale * vec4 (LB.normal, 0.0 ));
104
- var_FadeDepth = fadeDepth.zw ;
104
+ var_FadeDepth = fadeDepth.z / fadeDepth.w ;
105
105
#elif defined(USE_VERTEX_SPRITE)
106
106
vec4 fadeDepth = u_ModelViewProjectionMatrix * (position - depthScale * vec4 (LB.normal, 0.0 ));
107
- var_FadeDepth = fadeDepth.zw ;
107
+ var_FadeDepth = fadeDepth.z / fadeDepth.w ;
108
108
#endif
109
109
110
110
var_Color = color;
You can’t perform that action at this time.
0 commit comments