Skip to content

Commit

Permalink
Be more careful not to divide by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
szellmann committed Oct 28, 2024
1 parent f7243b9 commit dad4574
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions renderer/DirectLight_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ bool shade(ScreenSample &ss, Ray &ray, unsigned worldID,
mat, onDevice.samplers, attribs, hr.prim_id, tng, btng, sn);
}
color = getColor(mat, onDevice.samplers, attribs, hr.prim_id);

}

result.Ng = gn;
Expand Down Expand Up @@ -173,10 +174,10 @@ bool shade(ScreenSample &ss, Ray &ray, unsigned worldID,
viewDir,
ls.dir,
ls.intensity);
shadedColor = shadedColor * safe_rcp(ls.pdf) / ls.dist2;
shadedColor = shadedColor * safe_rcp(ls.pdf) * safe_rcp(1.f/ls.dist2);
}
else
shadedColor = hrv.albedo * ls.intensity * safe_rcp(ls.pdf) / ls.dist2;
shadedColor = hrv.albedo * ls.intensity * safe_rcp(ls.pdf) * safe_rcp(1.f/ls.dist2);
} else {
const auto &geom = onDevice.geometries[group.geoms[hr.geom_id]];
const auto &mat = onDevice.materials[group.materials[hr.geom_id]];
Expand All @@ -189,7 +190,7 @@ bool shade(ScreenSample &ss, Ray &ray, unsigned worldID,
viewDir,
ls.dir,
ls.intensity);
shadedColor = shadedColor * safe_rcp(ls.pdf) / ls.dist2;
shadedColor = shadedColor * safe_rcp(ls.pdf) * safe_rcp(1.f/ls.dist2);
}
}
else if (rendererState.renderMode == RenderMode::Ng)
Expand Down

0 comments on commit dad4574

Please sign in to comment.