Skip to content

Commit

Permalink
Add extra visbility test & fix incorrect gaussian sampling implementa…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
LeonKang130 committed Apr 21, 2024
1 parent faf00f0 commit 623aa52
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/integrators/restir_di.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,10 @@ class ReSTIRDirectLightingInstance final : public ProgressiveIntegrator::Instanc
}
void _perturb_sample(Expr<uint> frame_index, Expr<uint2> pixel_id, Expr<float> time) const noexcept {
auto constexpr num_perturb_iter = 10u;
auto constexpr sample_gaussian = [](Expr<float2> u) noexcept {
Float2 uu = u;
uu.x = 2.f * abs(u.x - .5f);
auto x = ite(u.x < .5f, -1.f, 1.f) * sqrt(-log(uu));
$if(any(dsl::isnan(x))) {
x = make_float2(0.f);
};
return x;
auto constexpr sample_box_muller = [](Expr<float2> u) noexcept {
auto r = sqrt(clamp(-2.f * log(u.x), 0.f, 1.f));
auto theta = 2.f * pi * u.y;
return make_float2(r * cos(theta), r * sin(theta));
};
sampler()->start(pixel_id, frame_index);
auto spectrum = pipeline().spectrum();
Expand All @@ -405,7 +401,7 @@ class ReSTIRDirectLightingInstance final : public ProgressiveIntegrator::Instanc
// offset the sample location on the light surface
$for(_, num_perturb_iter) {
auto candidate = reservoir;
auto perturbation = 0.01f * sample_gaussian(sampler()->generate_2d());
auto perturbation = 0.02f * sample_box_muller(sampler()->generate_2d());
candidate.sample.u_light_surface = clamp(reservoir.sample.u_light_surface + perturbation, 0.f, 1.f);
auto [L, pdf] = _evaluate_without_occlusion(candidate.sample, *it, wo, swl, time);
$if(reservoir.weight.target_pdf > 0.f & pdf > 0.f) {
Expand Down Expand Up @@ -545,6 +541,9 @@ class ReSTIRDirectLightingInstance final : public ProgressiveIntegrator::Instanc
if (node<ReSTIRDirectLighting>()->enable_decorrelation()) {
command_buffer << perturb(_total_frame_count, s.point.time).dispatch(resolution);
}
if (node<ReSTIRDirectLighting>()->enable_visibility_reuse()) {
command_buffer << visibility_reuse(_total_frame_count, s.point.time).dispatch(resolution);
}
}
if (node<ReSTIRDirectLighting>()->enable_spatial_reuse()) {
for (auto j = 0u; j < num_spatial_reuse_pass; j++) {
Expand Down

0 comments on commit 623aa52

Please sign in to comment.