Raymarching on a plane displaced by a heightmap

Hello,

I would like to share a technique a developed trying to breakdown an effect used by 404.zero.

The idea is quite simple: we define 2 parallel planes, facing the camera, the distance between the 2 planes will be the depth of the volume. We cast rays from the view to the first plane, and from there we march rays and sample the depth map until we reach either the 2nd plane, either a point that belong to the volume defined by the height map.

This technique can be useful if, like me, you work a lot in 2D, and if you want to add true depth to your scenes. You can also play with the lighting and get interesting results with it.

How to use it

Plug a depth map into the RAYMARCHING_PLANE node, and a color map (a constant color can work fine). In the settings of the “RAYMARCHING_PLANE” node, you will find 3 important settings under the raymarching tab:

  • depth: the distance between the front and far plane (if too high, the max number iteration of the raymarching shader needs to be upped)
  • precision: the length of the rays when the raymarching happens (too small and you won’t get far enough to find a surface, too big and you will miss some detail)
  • normal precision: the sample step when we compute the gradient of the height map to find the normal of the surface

Current limitations, please contribute if you can find a solution to these issues

I couldn’t find a way to compute soft shadows, only hard shadows. Also, the shadow tends to generate some artifacts, I couldn’t find a way to get rid of them (maybe this is due to the lack of precision of the depth map, when we march with the rays… but there might be somehing else I’m missing).

Only 1 light is supported in this version, but you can easily do your own lighting. I did it in another project by looping through a texture which contained the lights data, but since it’s a custom solution, it’s not part of this “generic” version.

plane-heightmap-starter.toe (7.1 KB)

I posted some work made using this technique on my instagram: https://instagram.com/ciphrd

Thanks for reading

5 Likes