mmp / pbrt-v3

Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
http://pbrt.org
BSD 2-Clause "Simplified" License
4.86k stars 1.18k forks source link

Two questions about spectral rendering and output #318

Open StefanMenzel opened 2 years ago

StefanMenzel commented 2 years ago

Hello,

First of all, thank you for the great book. It is a really useful read to understand spectral rendering in particular and the maths behind tracing. I have two questions that are hopefully easy to answer.

  1. How easy is it to modify the code to save spectral images as output instead of XYZ (or RGB)? From what I gather, I would 'just' have to grab them before the SampledSpectrum method ToXYZ computes XYZ from the spectra (the Rieman sum for equ. 5.1, chapter 5.2.1). I am aware the amount of data would much larger (eg 20 times that of RGB for 20 spectral points). It would be great to have this as a cmake option in pbrt v4.

  2. How easy is it to integrate optical dispersion, i.e. wavelength dependence of refractive index for realistic camera lenses? The realistic camera works well, but I would like to try and add dispersion to the lens materials. Would it be ok to have a look-up table n(lambda) and grab the corresponding refractive indices from it for each wavelength while tracing instead of assuming the refractive index as constant?

I am trying to get a feeling on how deep the coding rabbit hole is for those two suggested additions. (few lines of code or engine rewrite)

mmp commented 2 years ago
  1. Won't be an option in pbrt-v4, but it will be an exercise in the book. :-) One issue is that there isn't a widely adopted image file format standard for such images, though there's been recent progress on that front. It should be fairly easily to implement in pbrt-v4 via a new Film implementation.

  2. This should be quite easy, like tens of lines of code in RealisticCamera. You need to terminate all but the primary wavelength via a call to Spectrum::TerminateSecondary() and then do whatever you decide to figure out the IOR at each lens interface intersection. (The Cauchy equation or Sellmeier equation could be useful; see https://wiki.luxcorerender.org/Glass_Material_IOR_and_Dispersion#Refractive_Index_and_Dispersion_Data for useful discussion.)

KelSolaar commented 2 years ago

Hey Matt,

For 1, what about the EXR extensions proposed by Fichet et al. (2021): An OpenEXR Layout for Spectral Images

Cheers,

Thomas

mmp commented 2 years ago

@KelSolaar yep, that seems like the leading contender at this point!

StefanMenzel commented 2 years ago

thank you both for helping! It is good to know that both points 1. and 2. are rather easy to integrate.

For output I will probably just store all spectral data in the color channels of a couple of exr files for now. The Cauchy/Seilmeier fitting functions for dispersion look good. I was going to use a polynomial fit or just do a lookup table, but this looks better or more widely recognized.

mmp commented 2 years ago

FWIW I've implemented Fichet et al's OpenEXR spectral encoding in pbrt-v4 and just pushed it to github.

StefanMenzel commented 2 years ago

Thanks for that! Definitely looking forward to the v4 book release.