make intersection routines more robust vs NaNs
parent
b25a662f23
commit
93ed76211e
|
@ -196,7 +196,7 @@ public:
|
||||||
if (!m_sceneBSphere.rayIntersect(ray, nearT, farT))
|
if (!m_sceneBSphere.rayIntersect(ray, nearT, farT))
|
||||||
return Spectrum(0.0f);
|
return Spectrum(0.0f);
|
||||||
|
|
||||||
if (nearT >= 0 || farT <= 0)
|
if (!(nearT < 0 && farT > 0))
|
||||||
return Spectrum(0.0f);
|
return Spectrum(0.0f);
|
||||||
|
|
||||||
dRec.p = ray(farT);
|
dRec.p = ray(farT);
|
||||||
|
|
|
@ -145,11 +145,12 @@ public:
|
||||||
if (!solveQuadratic(A, B, C, nearT, farT))
|
if (!solveQuadratic(A, B, C, nearT, farT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (nearT > maxt || farT < mint)
|
if (!(nearT <= maxt && farT >= mint)) /* NaN-aware conditionals */
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const Float zPosNear = ray.o.z + ray.d.z * nearT;
|
const Float zPosNear = ray.o.z + ray.d.z * nearT;
|
||||||
const Float zPosFar = ray.o.z + ray.d.z * farT;
|
const Float zPosFar = ray.o.z + ray.d.z * farT;
|
||||||
|
|
||||||
if (zPosNear >= 0 && zPosNear <= m_length && nearT >= mint) {
|
if (zPosNear >= 0 && zPosNear <= m_length && nearT >= mint) {
|
||||||
t = nearT;
|
t = nearT;
|
||||||
} else if (zPosFar >= 0 && zPosFar <= m_length) {
|
} else if (zPosFar >= 0 && zPosFar <= m_length) {
|
||||||
|
|
|
@ -136,7 +136,7 @@ public:
|
||||||
m_worldToObject.transformAffine(_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)
|
if (!(hit >= mint && hit <= maxt))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Point local = ray(hit);
|
Point local = ray(hit);
|
||||||
|
|
|
@ -504,7 +504,7 @@ public:
|
||||||
if (!solveQuadraticDouble(A, B, C, nearT, farT))
|
if (!solveQuadraticDouble(A, B, C, nearT, farT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (nearT > maxt || farT < mint)
|
if (!(nearT <= maxt && farT >= mint)) /* NaN-aware conditionals */
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Next check the intersection points against the miter planes */
|
/* Next check the intersection points against the miter planes */
|
||||||
|
@ -523,7 +523,7 @@ public:
|
||||||
p = Point(rayO + rayD * nearT);
|
p = Point(rayO + rayD * nearT);
|
||||||
t = (Float) nearT;
|
t = (Float) nearT;
|
||||||
} else if (dot(pointFar - v1, n1) >= 0 &&
|
} else if (dot(pointFar - v1, n1) >= 0 &&
|
||||||
dot(pointFar - v2, n2) <= 0) {
|
dot(pointFar - v2, n2) <= 0) {
|
||||||
if (farT > maxt)
|
if (farT > maxt)
|
||||||
return false;
|
return false;
|
||||||
p = Point(rayO + rayD * nearT);
|
p = Point(rayO + rayD * nearT);
|
||||||
|
|
|
@ -127,7 +127,7 @@ public:
|
||||||
m_worldToObject.transformAffine(_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)
|
if (!(hit >= mint && hit <= maxt))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Point local = ray(hit);
|
Point local = ray(hit);
|
||||||
|
|
|
@ -172,8 +172,9 @@ public:
|
||||||
if (!solveQuadraticDouble(A, B, C, nearT, farT))
|
if (!solveQuadraticDouble(A, B, C, nearT, farT))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (nearT > maxt || farT < mint)
|
if (!(nearT <= maxt && farT >= mint)) /* NaN-aware conditionals */
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (nearT < mint) {
|
if (nearT < mint) {
|
||||||
if (farT > maxt)
|
if (farT > maxt)
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue