[WebGPU only] view SDF / isosurface within Babylon scene

For a few projects I’m working on, I need to work with signed distance functions alongside traditional meshes. It’s useful to quickly be able to view and navigate those ‘virtual’ scenes in Babylon. Options include 3d triangulation of the SDF world into bounded ‘chunks’, a la marching cubes / dual contouring and cousins; or raymarching a flat image and billboarding it in the scene. I chose the latter, which meant solving two problems:

  • have the virtual camera (that does the raymarching) mirror the Babylon camera
  • do some kind of depth test to have the SDF world not obscured by / in front of the Babylon scene where it shouldn’t be

Bullet point 2 was hurting my head when trying to write depth maps in post processing shader, so I had the idea to use screen-space triangulation – projecting a grid of faces along the raymarched depth map in realtime, basically – in a compute shader. A neat side effect is that lighting / shadows are also working in the Babylon world because the mesh is really 3d (it just doesn’t capture 3d detail that isn’t aligned with the camera).

It’s a horribly messy demo because that’s all I ever have time for, but try flying around in the world and playing with the parameters of this particular scene. It is a lot of fun I think :slight_smile:

4 Likes