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.75k stars 407 forks source link

Denoiser not being initialized for OptiX 8.0.0 #422

Open JoeHegartyNV opened 3 months ago

JoeHegartyNV commented 3 months ago

The commit 44a61fad814de0a95a4d582f0b0db20e89394360 broke the initialization of the OptiX denoiser in pbrt-v4\src\pbrt\gpu\denoiser.cpp

Previously there were two code blocks with calls to optixDenoiserCreate() inside a define #if #else #endif. This was changed to three blocks of code inside a define #if #elif #else #endif, but only the last two blocks contained calls to optixDenoiserCreate(), so for the first block used by OptiX 8.0.0 the denoiserHandle was not being initialized.

Easy fix, just add a #endif after the newly added #if that sets the denoiseAlpha parameter for 8.0.0, and change the subsequent #elif back to a #if

    OptixDenoiserOptions options = {};
#if (OPTIX_VERSION >= 80000)
    options.denoiseAlpha = OPTIX_DENOISER_ALPHA_MODE_COPY;
#endif

#if (OPTIX_VERSION >= 70300)
    if (haveAlbedoAndNormal)
        options.guideAlbedo = options.guideNormal = 1;

    OPTIX_CHECK(optixDenoiserCreate(optixContext, OPTIX_DENOISER_MODEL_KIND_HDR, &options,
                                    &denoiserHandle));
#else
    options.inputKind = haveAlbedoAndNormal ? OPTIX_DENOISER_INPUT_RGB_ALBEDO_NORMAL
                                            : OPTIX_DENOISER_INPUT_RGB;

    OPTIX_CHECK(optixDenoiserCreate(optixContext, &options, &denoiserHandle));

    OPTIX_CHECK(
        optixDenoiserSetModel(denoiserHandle, OPTIX_DENOISER_MODEL_KIND_HDR, nullptr, 0));
#endif