mmp / pbrt-v4

Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.
https://pbrt.org
Apache License 2.0
2.86k stars 446 forks source link

Reading and writing sampled spectrums #92

Open D-K-E opened 3 years ago

D-K-E commented 3 years ago

I was recently making a spectral renderer for my thesis, and I have used some parts of your code as well. I noticed that in the code base of pbrt3 you mention reading and writing of spds. I would like to know if you plan on implementing it for pbrt4 ? If yes, I am going to suggest Spectral Binary format. Its specification basically consists of a table with a paragraph: Link to specification. It is also acknowledged by CIE. I have also written a very very very simple header only parser for it if you are interested (shameless self promotion I know ... )

mmp commented 3 years ago

Are there any other tools that operate on those spectral binary files? (It looks like it is also specified to store reflectance values in [0,1], which is unfortunate, but hopefully that's ignored since it uses floats to store values.)

Writing out spectral images is currently left as an exercise; it's unlikely that we will have time to add that functionality at this point, but the exercise could mention that format as an option.

D-K-E commented 3 years ago

Well on .spb, not that I know of, no. I think CIE opted for projects to write their own parsers. Probably that was why the specification is so simple. However there are two other slightly more evolved formats (both acknowledged by CIE) who do come with their own libraries: AIX, and NVXML.

They are more complicated as can be seen from their corresponding documents. Both libraries are written in C++. The library for AIX distributes the header file along with a .dll. NVXML distributes the entire source code along with the specification.

Another quick note is that distributed specifications antedate CIE technical report by a large margin ( NVXML is from 2012, AIX is probably from 2006, CIE report dates to 2017). So I am not sure if distributed specifications are still relevant, and unfortunately I don't have the access to the contents of the CIE report to verify it. I would say for an exercise mentioning .spb format would be largely sufficient and maybe mentioning other formats in a further reading section could be nice.

cesss commented 3 years ago

Writing out spectral images is currently left as an exercise; it's unlikely that we will have time to add that functionality at this point, but the exercise could mention that format as an option.

Believe it or not, the first thing I checked when I just had my first glimpse at PBRT v4 was precisely to look at the image output code, because given that the renderer is now multispectral by default, I supposed you would be able to save the rendering before conversion to RGB.

And I admit I checked it, not only because that's an uncommon feature, but because of curiosity of what file format you choose for saving multispectral images. Doing it with TIFF is generally not recommended because such TIFFs can confuse other apps (unless you save a grayscale TIFF per band, which seems to be common practice in satellite imagery websites). Another possibility is EXR, as it allows arbitrary channels in deep images, but I'm not sure if multispectral and EXR are a good mix. JPEG 2000 seems to support multispectral, but I don't know the details. And the SPB format, which I just discovered in this thread, looks very simple to use, although I fully agree with @mmp about how unfortunate is to limit that format for reflectivities only, when it could be used for images as well.

It's a bit weird we are in 2021 and there's no format of choice for multispectral images.

mmp commented 2 years ago

FWIW I've just pushed a commit that adds a spectral film to pbrt-v4, using Fichet et al's encoding for spectral data in EXR files: https://jcgt.org/published/0010/03/01/.