Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log depth z fighting #6513

Merged
merged 2 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Source/Scene/ClassificationPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ define([
// Tesselation on ClassificationPrimitives tends to be low,
// which causes problems when interpolating log depth from vertices.
// So force computing and writing logarithmic depth in the fragment shader.
var disableGlPositionLogDepth = 'DISABLE_GL_POSITION_LOG_DEPTH';
// Re-enable at far distances to avoid z-fighting.
var disableGlPositionLogDepth = 'ENABLE_GL_POSITION_LOG_DEPTH_AT_HEIGHT';

var vsSource = new ShaderSource({
defines : [extrudedDefine, disableGlPositionLogDepth],
Expand Down
7 changes: 7 additions & 0 deletions Source/Shaders/Builtin/Functions/vertexLogDepth.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ void czm_updatePositionDepth() {
#if defined(LOG_DEPTH) && !defined(DISABLE_GL_POSITION_LOG_DEPTH)
v_logPositionEC = (czm_inverseProjection * gl_Position).xyz;

#ifdef ENABLE_GL_POSITION_LOG_DEPTH_AT_HEIGHT
if (length(v_logPositionEC) < 2.0e6)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works... I'm just wondering if there is anything special about 2.0e6 or if it just happens to be a good value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I zoomed in to the edge of the polygon and slowly zoomed out until I saw the z fighting. Tested with larger and smaller polygons than what was in the bug example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, thanks!

{
return;
}
#endif

gl_Position.z = log2(max(1e-6, 1.0 + gl_Position.w)) * czm_logFarDistance - 1.0;
gl_Position.z *= gl_Position.w;
#endif
Expand Down