Skip to content

Commit 9bafbe0

Browse files
authored
Update PathTracingCommon.js
1 parent f12032d commit 9bafbe0

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

js/PathTracingCommon.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,44 +2373,24 @@ float CheapTorusIntersect( vec3 rayOrigin, vec3 rayDirection, float torusHoleSiz
23732373
float t0, t1;
23742374
float t = INFINITY;
23752375
2376-
// Torus Inside (Hyperboloid)
2376+
// Torus Outside (partial Sphere, with top and bottom portions removed)
23772377
// quadratic equation coefficients
2378-
float a = (rd.x * rd.x) + (rd.z * rd.z) - (rd.y * rd.y);
2379-
float b = 2.0 * ((rd.x * ro.x) + (rd.z * ro.z) - (rd.y * ro.y));
2380-
float c = (ro.x * ro.x) + (ro.z * ro.z) - (ro.y * ro.y) - torusHoleSize;
2381-
2382-
solveQuadratic(a, b, c, t0, t1);
2378+
float a = dot(rd, rd);
2379+
float b = 2.0 * dot(rd, ro);
2380+
float c = dot(ro, ro) - (torusHoleSize + 2.0);
23832381
2384-
if (t1 > 0.0)
2385-
{
2386-
ip = ro + (rd * t1);
2387-
if (abs(ip.y) < 1.0)
2388-
{
2389-
n = vec3( ip.x, -ip.y, ip.z );
2390-
n = dot(rd, n) < 0.0 ? n : -n;
2391-
t = t1;
2392-
}
2393-
}
2382+
solveQuadratic(a, b, c, t0, t1);
23942383
23952384
if (t0 > 0.0)
23962385
{
23972386
ip = ro + (rd * t0);
23982387
if (abs(ip.y) < 1.0)
23992388
{
2400-
n = vec3( ip.x, -ip.y, ip.z );
2401-
n = dot(rd, n) < 0.0 ? n : -n;
2389+
n = ip;
24022390
t = t0;
24032391
}
24042392
}
24052393
2406-
// Torus Outside (partial Sphere, with top and bottom portions removed)
2407-
// quadratic equation coefficients
2408-
a = dot(rd, rd);
2409-
b = 2.0 * dot(rd, ro);
2410-
c = dot(ro, ro) - (torusHoleSize + 2.0);
2411-
2412-
solveQuadratic(a, b, c, t0, t1);
2413-
24142394
if (t1 > 0.0 && t1 < t)
24152395
{
24162396
ip = ro + (rd * t1);
@@ -2421,16 +2401,36 @@ float CheapTorusIntersect( vec3 rayOrigin, vec3 rayDirection, float torusHoleSiz
24212401
}
24222402
}
24232403
2404+
// Torus Inside (Hyperboloid)
2405+
// quadratic equation coefficients
2406+
a = (rd.x * rd.x) + (rd.z * rd.z) - (rd.y * rd.y);
2407+
b = 2.0 * ((rd.x * ro.x) + (rd.z * ro.z) - (rd.y * ro.y));
2408+
c = (ro.x * ro.x) + (ro.z * ro.z) - (ro.y * ro.y) - torusHoleSize;
2409+
2410+
solveQuadratic(a, b, c, t0, t1);
2411+
24242412
if (t0 > 0.0 && t0 < t)
24252413
{
24262414
ip = ro + (rd * t0);
24272415
if (abs(ip.y) < 1.0)
24282416
{
2429-
n = ip;
2417+
n = vec3( ip.x, -ip.y, ip.z );
2418+
n = dot(rd, n) < 0.0 ? n : -n;
24302419
t = t0;
24312420
}
24322421
}
24332422
2423+
if (t1 > 0.0 && t1 < t)
2424+
{
2425+
ip = ro + (rd * t1);
2426+
if (abs(ip.y) < 1.0)
2427+
{
2428+
n = vec3( ip.x, -ip.y, ip.z );
2429+
n = dot(rd, n) < 0.0 ? n : -n;
2430+
t = t1;
2431+
}
2432+
}
2433+
24342434
return t;
24352435
}
24362436
`;

0 commit comments

Comments
 (0)