Page MenuHome

Cycles: Add build option to enable a debugging feature for MIS
ClosedPublic

Authored by Sebastian Herholz (sherholz) on Nov 9 2021, 10:33 AM.

Details

Summary

This patch adds a CMake option "WITH_CYCLES_MIS_DEBUG" which builds cycles with a feature that allows debugging/selecting the direct-light sampling strategy.
The three options are:
fwd: forward path tracing (e.g., via BSDF or phase function)
nee: next-event estimation
mis: a multiple importance sampling combination of the previous two methods

Such a feature is useful for debugging light different sampling, evaluation, and pdf methods (e.g., for light sources and BSDFs).
The following example shows the classroom scene ideally all images should look the same:

This figure visualizes multiple problems with the light sources (e.g., nee and the ceiling over the lamps)

Via Python it is possible to select the direct light sampling method via:
scene.cycles.direct_light_sampling_type = "nee"

Diff Detail

Event Timeline

Brecht Van Lommel (brecht) requested changes to this revision.Nov 9 2021, 12:34 PM

Thanks! Looks like a useful feature for debugging.

CMakeLists.txt
414

Can you rename this to WITH_CYCLES_DEBUG? I'd like to use to potentially add more options.

intern/cycles/blender/addon/properties.py
222–224

To follow naming conventions, can you change it to:

('MULTIPLE_IMPORTANCE_SAMPLING', "Multiple Importance Sampling", "Multiple importance sampling is used to combine direct light contributions from next-event estimation and forward path tracing", 0),
('FORWARD_PATH_TRACING', "Forward Path Tracing", "Direct light contributions are only sampled using forward path tracing", 1),
('NEXT_EVENT_ESTIMATION', "Next-Event Estimation", "Direct light contributions are only sampled using next-event estimation", 2),
426

typo "distriubtion", but this description seems like it should be changed.

intern/cycles/kernel/integrator/shade_background.h
84–94

This logic is repeated a few times, I think it would make sense to add a float light_sample_mis_weight(KernelGlobals kg, const float forward_pdf, float nee_pdf) utility function for this in kernel/light/sample.h.

intern/cycles/kernel/types.h
485–489
DIRECT_LIGHT_SAMPLING_MIS = 0,
DIRECT_LIGHT_SAMPLING_FORWARD = 1,
DIRECT_LIGHT_SAMPLING_NEE = 2,

DIRECT_LIGHT_SAMPLING_NUM,
intern/cycles/scene/integrator.cpp
57–59
direct_light_sampling_type_enum.insert("multiple_importance_sampling", DLS_TYPE_MIS);
direct_light_sampling_type_enum.insert("forward_path_tracing", DLS_TYPE_FWD);
direct_light_sampling_type_enum.insert("next_event_estimation", DLS_TYPE_NEE);
This revision now requires changes to proceed.Nov 9 2021, 12:34 PM

Looks good now, I'll commit this to the master branch next week.

This revision is now accepted and ready to land.Nov 11 2021, 5:11 PM
Sebastian Herholz (sherholz) marked 4 inline comments as done.Nov 12 2021, 1:43 PM

Thanks, Brecht for the quick review.

intern/cycles/CMakeLists.txt
230

I added a space to add new defines based on the debug features a developer wants to enable/disable.

I'll tweak this a bit so the option also affects GPU rendering before committing, we need to pass along debug flags to kernel compilation there.