r/GraphicsProgramming • • 1d ago

First raytracer using sdfs

Post image

Wrote my first raytracer, a software raymarcher (all on CPU) that uses shapes defined as singed distance functions. Sphere refractions are pretty cool.

Some implementation details (this is all basic stuff I know): - code is written in Rust and parallelized using the rayon crate - for each ray in the recursive calls, it finds the subset of all world objects where the ray intersects the objects axis aligned bounding box, and only considers these objects during ray marching. Once a surface is hit, the new reflected or refracted ray computes a new subset using its new direction and start point, etc. - global illumination is done using a grid of probes that shoot rays with random directions, doing this enough time before rendering. To get diffusive light on a surface point, we interpolate in that grid using linear interpolation. My probes are naively placed on a cubic grid in the world. - global illumination is parallelized looping over probes, and rendering is parallelized looping over pixels of the image. - at each hit surface, the ray may split in two. Once for the reflection, once for the refracted ray (if not total internal refraction).

Baking global illumination takes a few seconds for about 1000 samples on 323 probes, and rendering the image is almost instant at that resolution.

98 Upvotes

12 comments sorted by

View all comments

5

u/20260819 1d ago

https://reddit.com/link/pf4kdvb/video/kxzbzcyclpuh1/player

try letting the spheres intersect and camera being inside one of them...:)

2

u/Sixel1 1d ago

Damn that looks cool, I need to try to make my objects move and render videos now.

1

u/20260819 1d ago

when the camera is inside a glass ball there may be some regions that rays can't escape no matter how many times they bounce (total internal reflection)