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

PointPrimitive flickers/disappears when disableDepthTestDistance is POSITIVE_INFINITY #8465

Closed
stacktracer opened this issue Dec 13, 2019 · 2 comments · Fixed by #8600
Closed

Comments

@stacktracer
Copy link

I am creating a PointPrimitive (not an Entity) like so:

var point = points.add( {
    position: Cesium.Cartesian3.fromDegrees( -60, 0, 0, viewer.scene.globe.ellipsoid ),
    pixelSize: 20,
    color: new Cesium.Color( 1, 0, 1, 1 ),
    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
    disableDepthTestDistance: Number.POSITIVE_INFINITY
} );

When the page first loads, the point is sometimes visible, sometimes not. In either case, if I rotate the globe for a few seconds (no particular direction -- just back and forth, up and down), the point flickers badly. Sometimes it disappears entirely, and stays invisible for tens of seconds. Sometimes it seems like the direction I drag matters (e.g. the point stays visible if I drag upward, but disappears if I drag to the left), but that could just be my imagination.

Sandcastle example: LINK

If I set disableDepthTestDistance to zero, the problem does not occur. However, in my application that causes other problems -- I have other primitives on the ellipsoid surface, whose vertices stick up a little bit, and the point can end up partially behind those vertices. Disabling the depth test seems like the right way to solve that problem ... but when the depth test is disabled, I encounter the problem described above.

I spent a while digging in the Cesium code, but I can't even figure out the general category of what's going on. The point doesn't seem to be occluded -- sometimes the issue is apparent even before the ellipsoid gets drawn ... nothing is being rendered but the point and the starry background, yet the point still flickers.

Browser: Firefox, Chromium
Operating System: Linux

@OmarShehata
Copy link
Contributor

Thanks for reporting this @stacktracer . This seems to be an issue with the way the PointPrimitiveCollectionVS disables depth distance when logarithmic depth buffer is on. If you turn off log depth viewer.scene.logarithmicDepthBuffer = false; it should stop the flickering.

This is the piece of code where the depth test is disabled:

https://github.com/AnalyticalGraphicsInc/cesium/blob/59110b8fe399e248aa813c1d68b7e8cf56b4bb2f/Source/Shaders/PointPrimitiveCollectionVS.glsl#L152-L166

When you set depth distance to positive infinity, disableDepthTestDistance gets set to -1.0. This happens here:

https://github.com/AnalyticalGraphicsInc/cesium/blob/59110b8fe399e248aa813c1d68b7e8cf56b4bb2f/Source/Scene/PointPrimitiveCollection.js#L616-L624

@stacktracer
Copy link
Author

@OmarShehata -- awesome! Disabling log-depth does indeed avoid the flickering issue.

I guess the log call introduces some precision error, which sometimes puts the point on the wrong side of the near clip plane?

I'm still catching up on the relevant concepts (logarithmic depth buffer is clever!) ... but naively it seems like the precision error could be avoided by checking for gl_Position.z == gl_Position.w, and setting the logged-depth to be right on the near plane. Although not sure how that behaves when there are multiple frustums ... still thinking ....

@kring kring mentioned this issue Feb 7, 2020
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants