Skip to content

Commit

Permalink
Improve orthographic projected depth precision in logdepthbuf mode
Browse files Browse the repository at this point in the history
gl_FragCoord.z is imprecise on some platforms, so this should write out a more precise depth value.
  • Loading branch information
Oletus committed Feb 24, 2020
1 parent fb7edb9 commit 11a92d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
`;
7 changes: 5 additions & 2 deletions src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11a92d0

Please sign in to comment.