CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.73k stars 3.45k forks source link

Entity incorrectly occluded when no tile is in view #10932

Open calogeromauceri opened 1 year ago

calogeromauceri commented 1 year ago

When the camera is below the ellipsoid minimumHeight and looking at an entity with no tiles in view, then the entity gets incorrectly occluded

Here is an example using moon terrain, where the camera is located in a region that goes below the mean radius. When the camera is above the mean ellipsoid radius the sphere on the sky (it might be a planet) and the sun are properly rendered. When the camera is below the mean ellipsoid radius the sphere and the sun are not rendered

Sandcastle example

The problem is in the occluder being used for checking if the entity is visible or not. https://github.com/CesiumGS/cesium/blob/main/packages/engine/Source/Scene/Scene.js#L1799-L1823

If no tile is in the current view the scene frame minimumTerrainHeight is set to 0, so the occluder bounding sphere radius is equal to the ellipsoid minimum radius which in this case is above the camera location, causing the camera to be "occluded". When tiles are visible (in the sandcastle above select "horizon"), then the scene frame minimumTerrainHeight is properly computed.

Browser: Any

Operating System: Any

ggetz commented 1 year ago

Thanks for the report @calogeromauceri! I believe you are correct in explaining why this is happening. This may be tricky to fix without a performance hit since, for a true fix, I think we'd need to iterate through additional tiles each update. @kring would you happen to have additional insight here?

kring commented 1 year ago

When there are no tiles, then perhaps the minimumTerrainHeight should be the planet's actual minimum terrain height, rather than 0?

calogeromauceri commented 1 year ago

I'm happy to help fixing this problem as long as I have some guideline on how to do it. @kring I think the solution you are proposing is a good one, but how do we know the minimum terrain height? should it be a setting parameter for the globe or is it possible to get it somehow querying the terrain provider?

calogeromauceri commented 1 week ago

Any updates on this issue? I'm happy to help if needed!

ggetz commented 1 week ago

Thanks @calogeromauceri.

how do we know the minimum terrain height?

ApproximateTerrainHeights, once loaded, contains minimum and maximum values for earth. This is an approximation, and not suitable for all terrain datasets (see this issue for more info), but it should address the earth.

Other than that, I don't believe it's trivial to get the minimum terrain height at runtime. Perhaps we could allow the user to specify these values themselves.

calogeromauceri commented 6 days ago

Thank you very much for your suggestion, @ggetz. Based on your hint, I’ve come up with a fix. I'll submit a pull request with my changes soon.

Note: I updated the sandcastle example to show the issue with latest Cesium version (currently 1.121)

sandcastle

calogeromauceri commented 6 days ago

@ggetz I just submitted a pull request for this issue #12190. The fix is pretty simple, hope it is accepted