Skip to content

Commit

Permalink
Mask BSDF: fix sampling weight to get correct gradients
Browse files Browse the repository at this point in the history
  • Loading branch information
bathal1 authored and njroussel committed Sep 25, 2023
1 parent 7d91235 commit ee87f1c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/bsdfs/mask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,15 @@ class MaskBSDF final : public BSDF<Float, Spectrum> {
bs.sampled_component = null_index;
bs.sampled_type = +BSDFFlags::Null;
bs.pdf = 1.f - opacity;
result = 1.f;
result = (1.f - opacity) / dr::detach(1.f - opacity);

Mask nested_mask = active && sample1 < opacity;
if (dr::any_or<true>(nested_mask)) {
sample1 /= opacity;
auto tmp = m_nested_bsdf->sample(ctx, si, sample1, sample2, nested_mask);
dr::masked(bs, nested_mask) = tmp.first;
dr::masked(result, nested_mask) = tmp.second;
dr::masked(result, nested_mask) = tmp.second * opacity / dr::detach(opacity);
dr::masked(bs.pdf, nested_mask) *= opacity;
}

return { bs, result };
Expand Down

0 comments on commit ee87f1c

Please sign in to comment.