Skip to content

Commit

Permalink
Fix rare NaN case in CosDPhi().
Browse files Browse the repository at this point in the history
Issue mmp#272, via Pascal Grittmann.
  • Loading branch information
mmp committed Jun 26, 2020
1 parent e5c7d6b commit 4f0a794
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ inline Float Cos2Phi(const Vector3f &w) { return CosPhi(w) * CosPhi(w); }
inline Float Sin2Phi(const Vector3f &w) { return SinPhi(w) * SinPhi(w); }

inline Float CosDPhi(const Vector3f &wa, const Vector3f &wb) {
return Clamp(
(wa.x * wb.x + wa.y * wb.y) / std::sqrt((wa.x * wa.x + wa.y * wa.y) *
(wb.x * wb.x + wb.y * wb.y)),
-1, 1);
Float waxy = wa.x * wa.x + wa.y * wa.y;
Float wbxy = wb.x * wb.x + wb.y * wb.y;
if (waxy == 0 || wbxy == 0)
return 1;
return Clamp((wa.x * wb.x + wa.y * wb.y) / std::sqrt(waxy * wbxy), -1, 1);
}

inline Vector3f Reflect(const Vector3f &wo, const Vector3f &n) {
Expand Down

0 comments on commit 4f0a794

Please sign in to comment.