CesiumGS / CesiumGS/cesium

Improve voxel depth testing

Open
#11,019 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

category - voxels
Dominant language
JavaScript
Stars
15.8k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

Currently voxels are always rendered above objects in the `OPAQUE` and `TRANSLUCENT` pass.

Some different options for improving this:

1. Render the `VOXELS` pass before the `OPAQUE` pass. This will have the opposite effect where opaque geometry will always render above voxels.
2. In [`IntersectDepth.glsl`](https://github.com/CesiumGS/cesium/blob/main/packages/engine/Source/Shaders/Voxels/IntersectDepth.glsl), read from the currently bound depth texture instead of `czm_globeDepthTexture`. The latter only includes depth from the `GLOBE` and `CESIUM_3D_TILE` passes, while the former includes depth from all previous passes. This might require some plumbing with textures, framebuffers on the JavaScript side.
3. Participate in depth testing the normal WebGL way. One way to do that is to write depth when the alpha becomes fully saturated and enable `depthTest` and `depthMask` in the [renderState](https://github.com/CesiumGS/cesium/blob/b68be0e5dbb42652ce64a3c54b482f571007b07f/packages/engine/Source/Scene/buildVoxelDrawCommands.js#L63-L74). The main problem with this approach is that the entire fragment gets discarded if the depth test fails, so any translucent color accumulation gets lost. Of course this wouldn't be a problem for fully opaque voxels.

And some future ideas:

* How do we handle different `VoxelPrimitives` depth testing against each other? Currently we don't: the `VoxelPrimitive` that's rendered last has priority.
* How do we handle translucency? `VoxelPrimitive` draw commands do not participate in OIT.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/engine/Source/Shaders/Voxels/IntersectDepth.glsl and packages/engine/Source/Scene/buildVoxelDrawCommands.js, then trace the voxel pass, depth texture, framebuffer, and renderState setup. Compare the three proposed approaches and determine how opaque and translucent voxels should interact with prior geometry. Done requires an agreed depth-testing design, implementation, and coverage for voxel depth behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.