File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed
src/engine/renderer/glsl_source Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ IN(smooth) vec2 var_TexCoords;
36
36
IN(smooth ) vec4 var_Color;
37
37
38
38
#if defined(USE_DEPTH_FADE)
39
- IN(smooth ) vec2 var_FadeDepth;
39
+ IN(smooth ) float var_FadeDepth;
40
40
uniform sampler2D u_DepthMap;
41
41
#endif
42
42
@@ -65,7 +65,14 @@ void main()
65
65
66
66
#if defined(USE_DEPTH_FADE)
67
67
float depth = texture2D (u_DepthMap, gl_FragCoord .xy / r_FBufSize).x;
68
- float fadeDepth = 0.5 * var_FadeDepth.x / var_FadeDepth.y + 0.5 ;
68
+
69
+ // convert z from normalized device coordinates [-1, 1]
70
+ // to window coordinates [0, 1]
71
+ float fadeDepth = 0.5 * var_FadeDepth + 0.5 ;
72
+
73
+ // HACK: the (distance from triangle to object behind it) / (shader's depthFade distance) ratio
74
+ // is calculated by using (nonlinear) depth values instead of the correct world units, so the
75
+ // fade curve will be different depending on the distance to the viewer and znear/zfar
69
76
color.a *= smoothstep (gl_FragCoord .z, fadeDepth, depth);
70
77
#endif
71
78
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ uniform mat4 u_ModelViewProjectionMatrix;
47
47
48
48
#if defined(USE_DEPTH_FADE)
49
49
uniform float u_DepthScale;
50
- OUT(smooth ) vec2 var_FadeDepth;
50
+ OUT(smooth ) float var_FadeDepth;
51
51
#endif
52
52
53
53
OUT(smooth ) vec2 var_TexCoords;
@@ -91,8 +91,8 @@ void main() {
91
91
92
92
#if defined(USE_DEPTH_FADE)
93
93
// compute z of end of fading effect
94
- vec4 fadeDepth = u_ModelViewProjectionMatrix * (position - u_DepthScale * vec4 ( LB.normal, 0.0 ) );
95
- var_FadeDepth = fadeDepth.zw ;
94
+ vec4 fadeDepth = u_ModelViewProjectionMatrix * ( position - u_DepthScale * vec4 (LB.normal, 0.0 ) );
95
+ var_FadeDepth = fadeDepth.z / fadeDepth.w ;
96
96
#endif
97
97
98
98
SHADER_PROFILER_SET
You can’t perform that action at this time.
0 commit comments