posted 23 Feb 2022

Ray Marcher


§ Ray Marcher

``

§ Implementation Details

The ray marcher above is being rendered in real-time in a WebGL2 context with a frag shader.

For performance reasons, the marcher is rendering to a 360 x 360 viewport that is upsampled to 720 x 720. To mask the blurriness and aliasing from upsampling and Monte Carlo, I used a dither filter by Shorakie on Shadertoy.

The shader does 12 passes (ray bounces) per fragment; for dielectric materials I implement a Monte-Carlo approach to choose whether to reflect or refract. As for the BRDF, I used the Cook-Torrence specular model combined with the normal Blinn-Phong diffuse.

The geometry is generated implicitly via signed distance functions (SDFs). With SDFs, we can use the finite difference method to quickly approximate the gradient of the apparent surface. Another benefit is that we can apply interpolation on the basic binary operations from constructive solid geometry (CSG); the consequence is that we can create complex smooth (sometimes organic like) geometries.