Last active
October 3, 2024 09:02
-
-
Save DomNomNom/46bb1ce47f68d255fd5d to your computer and use it in GitHub Desktop.
Ray-AABB (Axis Aligned Bounding Box) intersection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// adapted from intersectCube in https://github.com/evanw/webgl-path-tracing/blob/master/webgl-path-tracing.js | |
// compute the near and far intersections of the cube (stored in the x and y components) using the slab method | |
// no intersection means vec.x > vec.y (really tNear > tFar) | |
vec2 intersectAABB(vec3 rayOrigin, vec3 rayDir, vec3 boxMin, vec3 boxMax) { | |
vec3 tMin = (boxMin - rayOrigin) / rayDir; | |
vec3 tMax = (boxMax - rayOrigin) / rayDir; | |
vec3 t1 = min(tMin, tMax); | |
vec3 t2 = max(tMin, tMax); | |
float tNear = max(max(t1.x, t1.y), t1.z); | |
float tFar = min(min(t2.x, t2.y), t2.z); | |
return vec2(tNear, tFar); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That type name is absurdly long.