Spectral rendering, part 2: Real-time rendering Published 2025-11-13 Based on the insights from part 1, we have the means to define illuminant and reflectance spectra for our scene data. Then the color of a pixel arises from an integral over a product of spectra. The main goal of this blog post is to find efficient ways to evaluate such integrals using Monte Carlo integration and importance sampling. Additionally, we discuss how to define a BRDF based on known reflectance spectra, how to implement that and look at results. I have extended my educational path tracer to support both spectral and RGB rendering. You can take a look at this code to see specifics of how all of this is implemented (see the links at the bottom). A density for wavelength sampling As a reminder, we are interested in integrals of the form \[\begin{pmatrix}X\\Y\\Z\end{pmatrix} =\int_{360~\mathrm{nm}}^{830~\mathrm{nm}} \begin{pmatrix}\bar{x}(\lambda)\\ \bar{y}(\lambda)\\ \bar{z}(\lambda)\end{pmatrix} i(\lambda) \prod_{j=1}^{n-1} a_j(\lambda) \,\mathrm{d}\lambda\text{,}\] where \(i(\lambda)\) is an illuminant spectrum, \(a_1(\lambda),\ldots,a_{n-1}(\lambda)\) are surface reflectance spectra at each path vertex and \(\bar{x}(\lambda), \bar{y}(\lambda), \bar{z}(\lambda)\) are the CIE XYZ color matching functions. Out of that, we get the color for that path in the XYZ color space, which we can then convert to sRGB or another color space for display. We can also define RGB color matching functions to combine two steps into one: \[ \begin{pmatrix}\bar{r}(\lambda) \\ \bar{g}(\lambda) \\ \bar{b}(\lambda)\end{pmatrix} := \begin{pmatrix} 3.2406255 & \hspace{-0.9em}-1.5372080 & \hspace{-0.6em}-0.4986286 \\ -0.9689307 & \hspace{-0.9em}1.8757561 & \hspace{-0.6em}0.0415175 \\ 0.0557101 & \hspace{-0.9em}-0.2040211 & \hspace{-0.6em}1.0569959 \end{pmatrix} \hspace{-0.5em}\begin{pmatrix} \bar{x}(\lambda) \\ \bar{y}(\lambda) \\ \bar{z}(\lambda) \end{pmatrix} \] Then \[\begin{pmatrix}R_\mathrm{linear}\\G_\mathrm{li...
First seen: 2025-11-23 17:19
Last seen: 2025-11-24 00:20