From e1ff84e0a984a89894f2c238014c91399fb14a98 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Fri, 12 Oct 2012 18:25:22 -0400 Subject: [PATCH] minor robustness improvements --- src/libbidir/mut_manifold.cpp | 2 ++ src/librender/skdtree.cpp | 5 +++++ src/shapes/disk.cpp | 23 ++++++++++++----------- src/shapes/rectangle.cpp | 19 ++++++++++--------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/libbidir/mut_manifold.cpp b/src/libbidir/mut_manifold.cpp index 36baf6a4..9fdc9493 100644 --- a/src/libbidir/mut_manifold.cpp +++ b/src/libbidir/mut_manifold.cpp @@ -669,6 +669,8 @@ Float ManifoldPerturbation::Q(const Path &source, const Path &proposal, source.vertex(a)->pdf[mode] * m_probFactor * m_probFactor); Float pdf = source.vertex(a+step)->perturbPositionPdf(proposal.vertex(a+step), stddev); + if (pdf == 0) + return 0.0f; weight /= pdf; } diff --git a/src/librender/skdtree.cpp b/src/librender/skdtree.cpp index 236b72c0..83fad551 100644 --- a/src/librender/skdtree.cpp +++ b/src/librender/skdtree.cpp @@ -128,6 +128,11 @@ bool ShapeKDTree::rayIntersect(const Ray &ray, Intersection &its) const { if (EXPECT_TAKEN(maxt > mint)) { if (rayIntersectHavran(ray, mint, maxt, its.t, temp)) { fillIntersectionRecord(ray, temp, its); + if (std::isnan(its.t)) { + cout << ray.toString() << endl; + cout << its.toString() << endl; + Log(EError, "Whaat?!"); + } return true; } } diff --git a/src/shapes/disk.cpp b/src/shapes/disk.cpp index 343ea8db..35c74894 100644 --- a/src/shapes/disk.cpp +++ b/src/shapes/disk.cpp @@ -134,25 +134,26 @@ public: inline bool rayIntersect(const Ray &_ray, Float mint, Float maxt, Float &t, void *temp) const { Ray ray; m_worldToObject.transformAffine(_ray, ray); - Float hit = -ray.o.z/ray.d.z; + Float hit = -ray.o.z / ray.d.z; if (hit < mint || hit > maxt) return false; Point local = ray(hit); - if (local.x * local.x + local.y * local.y > 1) + if (local.x * local.x + local.y * local.y <= 1) { + t = hit; + + if (temp) { + Float *data = static_cast(temp); + data[0] = local.x; + data[1] = local.y; + } + + return true; + } else { return false; - - t = hit; - - if (temp) { - Float *data = static_cast(temp); - data[0] = local.x; - data[1] = local.y; } - - return true; } bool rayIntersect(const Ray &ray, Float mint, Float maxt) const { diff --git a/src/shapes/rectangle.cpp b/src/shapes/rectangle.cpp index c4055818..1389b5e5 100644 --- a/src/shapes/rectangle.cpp +++ b/src/shapes/rectangle.cpp @@ -125,25 +125,26 @@ public: inline bool rayIntersect(const Ray &_ray, Float mint, Float maxt, Float &t, void *temp) const { Ray ray; m_worldToObject.transformAffine(_ray, ray); - Float hit = -ray.o.z/ray.d.z; + Float hit = -ray.o.z / ray.d.z; if (hit < mint || hit > maxt) return false; Point local = ray(hit); - if (std::abs(local.x) > 1 || std::abs(local.y) > 1) - return false; + if (std::abs(local.x) <= 1 && std::abs(local.y) <= 1) { + t = hit; - t = hit; + if (temp) { + Float *data = static_cast(temp); + data[0] = local.x; + data[1] = local.y; + } - if (temp) { - Float *data = static_cast(temp); - data[0] = local.x; - data[1] = local.y; + return true; } - return true; + return false; } bool rayIntersect(const Ray &ray, Float mint, Float maxt) const {