diff --git a/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js b/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js index 1ab95c428e95d7..3da54de9a7a2bb 100644 --- a/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +++ b/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js @@ -3,7 +3,7 @@ export default /* glsl */` // Doing a strict comparison with == 1.0 can cause noise artifacts // on some platforms. See issue #17623. - gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5; + gl_FragDepthEXT = vIsPerspective == 0.0 ? vFragDepth : log2( vFragDepth ) * logDepthBufFC * 0.5; #endif `; diff --git a/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js b/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js index e1b4d21e074820..00834f67cca5ae 100644 --- a/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +++ b/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js @@ -3,8 +3,11 @@ export default /* glsl */` #ifdef USE_LOGDEPTHBUF_EXT - vFragDepth = 1.0 + gl_Position.w; - vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) ); + bool isPerspective = isPerspectiveMatrix( projectionMatrix ); + + vIsPerspective = float( isPerspective ); + + vFragDepth = isPerspective ? 1.0 + gl_Position.w : gl_Position.z * 0.5 + 0.5; #else