<p>I want to add spectral rendering and dispersion to my pathtracer. I found the <a href="https://cgg.mff.cuni.cz/%7Ewilkie/Website/EGSR_14_files/WNDWH14HWSS.pdf" rel="nofollow noreferrer">Hero Wavelength paper</a> but I have trouble implementing this. This is how I understand the process and where I am stuck:</p>
<ul>
<li>When generating a ray, randomly sample a hero wavelength <span class="math-container">$\lambda_h$</span> with probability <span class="math-container">$p(\lambda_h)$</span>. Is uniform sampling good enough?</li>
<li>Now, generate <span class="math-container">$C$</span> other wavelengths (a spectrum) using the rotation function <span class="math-container">$r_j$</span>. Do we generate <span class="math-container">$C$</span> others, or <span class="math-container">$C-1$</span> so that in total there are <span class="math-container">$C$</span> wavelengths?</li>
<li>In the integrator when the BSDF contribution is evaluated, sample <em>one</em> of those <span class="math-container">$C$</span> wavelengths and call it <span class="math-container">$\lambda_s$</span>. Does this include the hero wavelength? Are they sampled uniformly?</li>
<li>Evaluate the BSDF for <span class="math-container">$\lambda_s$</span> 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: <span class="math-container">$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)}$</span> but where does the probability <span class="math-container">$p(X_i | \lambda_i^k)$</span> come from? Do I have to evaluate the BSDF direction for each wavelength to get a probability of choosing this path?</li>
<li>Generate the next path direction based on the BSDF and the hero wavelength.</li>
</ul>
<p>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:</p>
<ul>
<li>compute IOR based on wavelength and the dispersion formula for a given material</li>
<li>compute fresnel with this new IOR</li>
<li>use a wavelength to RGB conversion to compute the material contribution</li>
</ul>
<p><a href="https://i.sstatic.net/mRtIn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mRtIn.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-01-07T05:06:35.607Z
Not the most informative comment, but if you are not obliged to use hero sampling in anyway, try first sampling visible wave length range uniformly. It takes more time to render scenes but way easier to implement. Your color values just transform into power values as floating points that fills the visible wave length range. I can show post a link to a project of mine in github as well if you like ?
Kaan E.
CC BY-SA 4.0
2021-02-10T14:18:28.750Z
1. Uniform sampling is fine, but you can do better. 2. You want C total wavelengths. 3. The hero wavelength should be picked before any ray intersections happen. You don't change the hero wavelength between bounces. 4. The basic idea is that you have C BSDF evaluations (one per wavelength), C BSDF pdfs etc, but the direction of the new ray is based on the hero wavelength ONLY, and then combine results later with MIS.
64_
<pathtracing><importance-sampling><spectral>
Hero wavelength multiple importance sampling
lyinch
# Hero wavelength multiple importance sampling

(Asked by: username_0 on 2020-12-05)

I want to add spectral rendering and dispersion to my pathtracer. I found the [Hero Wavelength paper](https://cgg.mff.cuni.cz/%7Ewilkie/Website/EGSR_14_files/WNDWH14HWSS.pdf) 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

[![enter image description here](https://i.sstatic.net/mRtIn.png)](https://i.sstatic.net/mRtIn.png)

**Tags:** pathtracing, importance-sampling, spectral

> **Comments:**
> **username_1**: Not the most informative comment, but if you are not obliged to use hero sampling in anyway, try first sampling visible wave length range uniformly. It takes more time to render scenes but way easier to implement. Your color values just transform into power values as floating points that fills the visible wave length range. I can show post a link to a project of mine in github as well if you like ?  
> **username_2**: 1. Uniform sampling is fine, but you can do better. 2. You want C total wavelengths. 3. The hero wavelength should be picked before any ray intersections happen. You don't change the hero wavelength between bounces. 4. The basic idea is that you have C BSDF evaluations (one per wavelength), C BSDF pdfs etc, but the direction of the new ray is based on the hero wavelength ONLY, and then combine results later with MIS.  

---

## 0 answers

