I want to add spectral rendering and dispersion to my pathtracer. I found the Hero Wavelength paper but I have trouble implementing this. This is how I understand the process and where I am stuck:
- When generating a ray, randomly sample a hero wavelength $\lambda_h$ with probability $p(\lambda_h)$. Is uniform sampling good enough?
- Now, generate $C$ other wavelengths (a spectrum) using the rotation function $r_j$. Do we generate $C$ others, or $C-1$ so that in total there are $C$ wavelengths?
- In the integrator when the BSDF contribution is evaluated, sample one of those $C$ wavelengths and call it $\lambda_s$. Does this include the hero wavelength? Are they sampled uniformly?
- Evaluate the BSDF for $\lambda_s$ and add the contribution, weighted by the MIS weight and the probability of choosing this wavelength. How is the MIS weight computed? The paper says: $w_s(X_i, \lambda_i^s) = \frac{p(\lambda_i^h) p(X_i | \lambda_i^h)}{\sum_{k=1}^C p(\lambda_i^k) p(X_i | \lambda_i^k)}$ but where does the probability $p(X_i | \lambda_i^k)$ come from? Do I have to evaluate the BSDF direction for each wavelength to get a probability of choosing this path?
- Generate the next path direction based on the BSDF and the hero wavelength.
My current implementation doesn't really differ from the single wavelength per ray model and has lots of coloured noise. As for the dielectric, I do:
- compute IOR based on wavelength and the dispersion formula for a given material
- compute fresnel with this new IOR
- use a wavelength to RGB conversion to compute the material contribution
