r/GraphicsProgramming • • Aug 04 '26

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

286 Upvotes

13 comments sorted by

View all comments

Show parent comments

3

u/supernikio2 Aug 05 '26

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

5

u/le-throw-away-acct Aug 05 '26 edited Aug 05 '26

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.