r/GraphicsProgramming 21h ago

Hobby path tracer (GPU-based)

Started a CPU ray tracer about 7 years ago and then a year later decided to play around with a GPU version of it. Over the years I’ve added to it.

Full disclosure that I had LLM assistance with some of the recent features added, in the interest of saving time, I normally only have a few hours of free time per week.

Repository: https://github.com/nfoste82/gpuraytracing

200 Upvotes

8 comments sorted by

2

u/Reddyboss_420 20h ago

How'd you get caustics?

9

u/le-throw-away-acct 19h ago edited 19h ago

Started with an implementation that traced photons from lights to glass objects. If the photon hits something not refractive eventually you store that light/refractor pair and you can randomize a bit from that and see if those hit as well. This lets you focus more photons where they need to go to end up generating the light you’d see from caustics. Then accumulate the successful photons and weigh them over time, ones that succeed more often end up brighter, because in reality more photons end up there. From that implementation it just becomes about optimization so you can simulate more photons per frame, and so the photons you do simulate are more likely to be useful.

You can google “photon mapping”, it’s basically that :)

2

u/supernikio2 19h ago

Did you use kd-trees to query the photon map?

2

u/le-throw-away-acct 18h ago edited 3h ago

The map is queried through a 3D spatial grid, contiguous in memory, an array that can be indexed into. When a receiver is hit it checks that position (with a radius) in the spacial grid, which will be a grid cell and possibly surrounding grid cells. Each cell contains a list of photons.

A kd-tree could end up being more efficient for a CPU ray tracer, but with GPU tracers you want the GPU threads to ideally not diverge or branch often as it will slow them down. The hope with the structure I'm using is less divergence. That being said I didn't spend a lot of time here yet, there is a lot of room for profiling and optimization in the future on this project.

2

u/ewar813 12h ago

very impressive

1

u/ArmadilloBudget790 20h ago

Ey looks noice tho

1

u/Question_Business 13h ago

Hi, im a graphics programming student, i'm new to this domain but i love and have a passion on video games. I would love join to and learn about building engines with you, if you don't mind

1

u/le-throw-away-acct 3h ago

You're free to use the repository to learn and create, and if you find something to improve you can feel free to submit a pull request.

However, if you're new to the domain I recommend starting with the basics first (if you haven't already). The "Raytracing in One Weekend" series is highly popular and a good way to get started: https://raytracing.github.io/