Improve voxel depth testing
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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