I am working on a ray marcher in CesiumJS. It works fairly well, but I am experiencing an issue, that I think might be linked to Cesium’s depth texture in a PostProcessStage’s fragment shader.
I created a minimal example so you can try it out: Sandcastle example. In this example, I want to display the shadow of a cube on the terrain. For each fragment, I shoot a ray from the computed world coordinates of the terrain at that fragment location towards the sun, and display the fragment as black if the ray goes through the cube at some point. This works fairly well, but there are weird artefacts while moving or zooming. There doesn’t seem to be issues while standing still. The artefacts get bigger the further away the viewer (camera) is from the terrain. It looks like it could be some sort of depth buffer lack of precision while moving, maybe done to improve performance, but I am not sure at all.
Here are a few screen recordings showing the issue from different standpoints:
- Final shadow view: shadow
- Terrain eye coordinates depth: depth
- Terrain world coordinates: world coordinates
You can change the “MODE” in the Sandcastle example to switch to eye coordinates depth or world coordinates view.
Do you have an idea how I could eliminate or mitigate the issue? Maybe disable a performance flag somewhere?