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.81k stars 433 forks source link

Spectral renderer crashing on GPU #308

Closed johnson-c closed 1 year ago

johnson-c commented 1 year ago

I want to use PBRT to model atomic emission from fusion plasmas so I want to use the spectral renderer. I can get the scenes in "pbrt-v4-volumes" to render using a gpu. These scenes are all RGB. I can get a test case spectral scene I made to render using the CPU but when I try the same scene with a GPU I get a core dump.

When I build it debug mode both CPU and GPU spectral renders crash so I not sure the output is meaningful? Is there an example of a known working gpu spectral renderer? All of the examples I've seen are RGB.

Attached is the scene that I am testing with, its just a modification of the "rainbow_box" from pbrt-v4-volumes and then some test grid data from a plasma simulation. The image is from running the CPU version without debugging.

I'm running on a fresh Ubuntu 22.04 install.

gpu_debug_output.txt cpu_debug_output.txt test.pbrt.txt rainbow_box_s.pbrt.txt

rainbow_box_s

johnson-c commented 1 year ago

I should also say that the crash is happening after the rendering is done

(base) curtis@wopr:~/pbrt/build$ ./pbrt --gpu ../../Downloads/pbrt-v4-volumes-main/scenes/rainbow_box/rainbow_box_s.pbrt
pbrt version 4 (built Nov 15 2022 at 00:36:46) Copyright (c)1998-2021 Matt Pharr, Wenzel Jakob, and Greg Humphreys. The source code to pbrt (but not the book contents) is covered by the Apache 2.0 License. See the file LICENSE.txt for the conditions of the license. Rendering: [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++] (4.7s)
Segmentation fault (core dumped)

shadeops commented 1 year ago

Oh this is interesting.

The problem comes from "spectrum Le" [500 1 ]

When the parameters are evaluated, it sees this and creates a PiecewiseLinearSpectrum, which has trouble given that there is only one spectrum sample. In fact, this problem arises in Materials and Textures too.

For example in this scene, you'd expect the sphere to render as gray (0.5) but it actually renders black -

Film "rgb"
    "integer yresolution" [ 400 ]
    "integer xresolution" [ 400 ]
    "string filename" [ "pbrt.exr" ]

LookAt 0 0 10
       0 0 0
       0 1 0

Camera "perspective"
    "float screenwindow" [ -1 1 -1 1 ]
    "float fov" [ 45 ]

WorldBegin

AttributeBegin
    LightSource "infinite"
        "float scale" [ 1 ]
AttributeEnd

AttributeBegin
   Material "diffuse" "spectrum reflectance" [ 500 0.5 ]
   Shape "sphere"
       "float radius" [ 1 ]
AttributeEnd

I created a PR, #309 , which I believe addresses this. When the parameters are being evaluated if the number of spectrum samples is just one (constant) it builds a ConstantSpectrum

With the above PR, your scene no longer crashes and the sphere example no longer renders as black.

johnson-c commented 1 year ago

Interesting, I guess you find bugs when you have no idea what you're doing!


Related I'm trying model plasma emission so there is no absorption/scatter of the emitted light (at least at the densities I'm trying to model). I believe this means that I should set "float scale" [0] (accidentally had it set twice in the input file) but when I do this nothing renders am I missing something? Same thing if set sigma_a and sigma_s to zero individually. From my reading of the documentation I thought that "Le" and "density" would control the emission?

mmp commented 1 year ago

I've (finally) added a warning about likely-unintended single wavelength spectral specifications, in case other folks are surprised by this.