SDF Ray Tracing
- 3 Devlogs
- 7 Total hours
Ray tracing engine which uses Signed Distance Fields
Ray tracing engine which uses Signed Distance Fields
Added shadows, another ray is just traced from the original hit towards the “sun”, and if it passes close to objects or hits objects, the colour is multiplied by some kind of factor. It was a great pain stopping the shadow ray intersecting the shape that was hit instantly, making everything look dark, as the start position must be moved out of the shape, but that can cause artifacts. This was fixed with a “bias” variable, which determines how steep the intersection was, and moves the position out of the shape accordingly.
Not much progress this time, just normals for lighting, but I discovered the SDF of a ‘Mandelbulb’; a 3D version of a Mandelbrot fractal. I don’t really understand the function, but it produces the image underneath.
I have set up WGPU with Rust to run a compute shader to render to a texture, which is then rendered to the screen. The compute shader ray traces using signed distance functions, stepping as far as the closest object at a time.
There is also a simple, FPS-style camera implementation, so the scene can be looked around.
Next, I plan to improve the graphics, with basic lighting and shadows, and perhaps materials instead of colours.
I’m not sure where this project will go, but hopefully something interesting will come of it.
The picture shows a sphere and long cuboid, a smin function used on them, with different parameters, causes them to blend. This is only one of the many interesting properties of SDFs.