Skip to content

Commit

Permalink
Update PathTracingCommon.js
Browse files Browse the repository at this point in the history
  • Loading branch information
erichlof committed Apr 2, 2024
1 parent 288bd80 commit 2f3ab14
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions js/PathTracingCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2373,44 +2373,24 @@ float CheapTorusIntersect( vec3 rayOrigin, vec3 rayDirection, float torusHoleSiz
float t0, t1;
float t = INFINITY;
// Torus Inside (Hyperboloid)
// Torus Outside (partial Sphere, with top and bottom portions removed)
// quadratic equation coefficients
float a = (rd.x * rd.x) + (rd.z * rd.z) - (rd.y * rd.y);
float b = 2.0 * ((rd.x * ro.x) + (rd.z * ro.z) - (rd.y * ro.y));
float c = (ro.x * ro.x) + (ro.z * ro.z) - (ro.y * ro.y) - torusHoleSize;
solveQuadratic(a, b, c, t0, t1);
float a = dot(rd, rd);
float b = 2.0 * dot(rd, ro);
float c = dot(ro, ro) - (torusHoleSize + 2.0);
if (t1 > 0.0)
{
ip = ro + (rd * t1);
if (abs(ip.y) < 1.0)
{
n = vec3( ip.x, -ip.y, ip.z );
n = dot(rd, n) < 0.0 ? n : -n;
t = t1;
}
}
solveQuadratic(a, b, c, t0, t1);
if (t0 > 0.0)
{
ip = ro + (rd * t0);
if (abs(ip.y) < 1.0)
{
n = vec3( ip.x, -ip.y, ip.z );
n = dot(rd, n) < 0.0 ? n : -n;
n = ip;
t = t0;
}
}
// Torus Outside (partial Sphere, with top and bottom portions removed)
// quadratic equation coefficients
a = dot(rd, rd);
b = 2.0 * dot(rd, ro);
c = dot(ro, ro) - (torusHoleSize + 2.0);
solveQuadratic(a, b, c, t0, t1);
if (t1 > 0.0 && t1 < t)
{
ip = ro + (rd * t1);
Expand All @@ -2421,16 +2401,36 @@ float CheapTorusIntersect( vec3 rayOrigin, vec3 rayDirection, float torusHoleSiz
}
}
// Torus Inside (Hyperboloid)
// quadratic equation coefficients
a = (rd.x * rd.x) + (rd.z * rd.z) - (rd.y * rd.y);
b = 2.0 * ((rd.x * ro.x) + (rd.z * ro.z) - (rd.y * ro.y));
c = (ro.x * ro.x) + (ro.z * ro.z) - (ro.y * ro.y) - torusHoleSize;
solveQuadratic(a, b, c, t0, t1);
if (t0 > 0.0 && t0 < t)
{
ip = ro + (rd * t0);
if (abs(ip.y) < 1.0)
{
n = ip;
n = vec3( ip.x, -ip.y, ip.z );
n = dot(rd, n) < 0.0 ? n : -n;
t = t0;
}
}
if (t1 > 0.0 && t1 < t)
{
ip = ro + (rd * t1);
if (abs(ip.y) < 1.0)
{
n = vec3( ip.x, -ip.y, ip.z );
n = dot(rd, n) < 0.0 ? n : -n;
t = t1;
}
}
return t;
}
`;
Expand Down

0 comments on commit 2f3ab14

Please sign in to comment.