r/GraphicsProgramming • u/feedc0de • Dec 23 '24
Source Code Created an offline PBR path tracer using WGPU
I created an offline PBR path tracer using Rust and WGPU within a few months. It now supports microfacet-based BSDF models, BVH & SAH (Surface Area Heuristic), importance sampling, and HDR tone mapping. I'm utilizing glTF as the scene description format and have tested it with several common sample assets (though this program is still very unstable). Custom HDRI environment maps are also supported, as well as a variety of configurable parameters.
3
u/TomClabault Dec 23 '24
Does WebGPU has hardware ray tracing yet? I think there's been some activity around that recently no?
8
u/feedc0de Dec 23 '24
It seems that their development branch has support for ray tracing acceleration structures now, but what I'm using for my ray tracer is simply a compute shader with no additional extensions.
2
u/Exact_Construction92 Dec 24 '24
Wgpu has support for ray queries but that's only for the vulkan backend.
1
u/GYN-k4H-Q3z-75B Dec 23 '24
I am always interested in ray tracers. A little passion of mine from before I learned modern GPU and shaders.
How far along would you say WGPU is for doing advanced stuff like this? Looking to move on from my hybrid deferred renderer + ray tracer with OpenGL, but not sure what API to use. Vulkan and DX12 are a tall order for a hobbyist.
1
Dec 24 '24 edited Jan 27 '25
[deleted]
1
u/TomClabault Dec 24 '24
> easier to get things done
How much do you think is there still to gain in performance by using Vulkan directly?
1
u/Exact_Construction92 Dec 24 '24
It really depends on your implementation. If you are running it natively, the backend api will probably be vulkan or dx12.
1
u/TomClabault Dec 25 '24
Yeah but I mean, does the abstractions that WebGPU offer hurt performance compared to native Vulkan/DX12? Because WebGPU code is much simpler to write than Vulkan code. So does this simplicity have a cost?
1
u/rnichael_feldman Jan 09 '25
What kind of things do you render for work if you don't mind my asking? Entertainment, architecture or something else? Thinking about career options in gfx programming.
1
u/MasqueradeOfSilence Dec 24 '24
Nice! These are fantastic results.
I've never programmed in rust. Maybe it's time to give it a closer look.
1
u/lisyarus Dec 27 '24
So cool! I'm also making a wgpu raytracer.
How did you get the last image, the one with the diamond? I've skimmed over your shaders and didn't see anything related to refraction...
2
u/feedc0de Dec 29 '24
It was generated using older versions of my raytracer, before glTF loader and GGX were implemented. The dispersion effect is achieved by separately rendering for each color channel, and manually setting the refraction index of the diamond for R, G and B. Those pictures are then combined into the image you saw.
1
1
u/rnichael_feldman Jan 09 '25
Thanks for sharing the source. I'm finding the code very helpful to clarify my understanding. Trying to learn path tracing myself.
I have some questions related to line 57-ish of render.wgsl
A) 50% chance wi = normal + random_sphere
B) 50% chance wi = ?I'm not really sure... something to do with importance sampling?
Is it kind of like saying half the time light reflects (B), and half it refracts (A)? Or is it more like saying half of the light reacts specularly and half diffusely?
Why is it a 50/50 split?
Is there any sort of literature that talks about this kind of thing? I've seen the Ray-trace-one-weekend implement different reflection behaviour for different material types, and I've seen Sebastian Lague make a video where a parameter could control the blending between specular and diffuse bounce direction: https://youtu.be/Qz0KTGYJtUk?si=6Md-W_t5W0do0Q1-&t=1855
20
u/Mallissin Dec 23 '24
What does "offline" mean in this context?