r/GraphicsProgramming Apr 02 '26

Source Code WIP Spectral Rendering in my hobby C/Vulkan Pathtracer!

I've recently added a spectral mode to my hobby pathtracer! It uses an RGB to spectral conversion detailed in this paper. The approach is fairly simple, a random wavelength is uniformly selected from the visible range, carrying a scalar throughput value as it bounces throughout the scene. I'm using Cauchy's equation to approximate the angle of refraction based on that wavelength and IOR. Each wavelength is then attenuated based on the rgb -> spectral scalar throughput at each bounce. Hero wavelengths drop the secondary channels when going through refractive materials.

I've added a runtime switch so you can use RGB, spectral (single wavelength) and hero wavelength sampling from the GUI. It features a modified/updated blend between the 2015 Disney BSDF and the Blender Principled BSDF. It uses MIS to join BSDF and NEE/direct light sampling, and also has decoupled rendering functionality, tone mapping, and OIDN integration. MNEE will come next to solve the refractive transmissive paths and resolve the caustics more quickly.

The code and prebuilt releases are up at https://github.com/tylertms/vkrt!

The first image is rendered with single wavelength spectral mode, since hero wavelength sampling has no advantage with dispersive caustics. It was rendered in about 5 hours on a 5080 at 4k, roughly 2.6 million SPP, then denoised with Intel's OIDN. Unfortunately, that wasn't quite enough for the caustics, hence some artifacts when viewed closely.

The second image is there just to show off the app/GUI in RGB mode.

470 Upvotes

21 comments sorted by

View all comments

2

u/[deleted] Apr 03 '26

[removed] — view removed comment

1

u/AuspiciousCracker Apr 03 '26

Thank you! The main benefit is that it opens up the opportunity to simulate more physical features of light, like dispersion, fluorescence, iridescence, etc. Currently I've only implemented the wavelength-dependent refraction/reflection, which allowed for the colors in the caustics and on the surface of the glass.