Created
April 3, 2017 02:32
-
-
Save unitycoder/2cc493b2b207ce3520fcf68f30ebfe7f to your computer and use it in GitHub Desktop.
fast-branchless-raybounding-box-intersections
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
| // https://tavianator.com/fast-branchless-raybounding-box-intersections/ | |
| bool intersection(box b, ray r) { | |
| double tx1 = (b.min.x - r.x0.x)*r.n_inv.x; | |
| double tx2 = (b.max.x - r.x0.x)*r.n_inv.x; | |
| double tmin = min(tx1, tx2); | |
| double tmax = max(tx1, tx2); | |
| double ty1 = (b.min.y - r.x0.y)*r.n_inv.y; | |
| double ty2 = (b.max.y - r.x0.y)*r.n_inv.y; | |
| tmin = max(tmin, min(ty1, ty2)); | |
| tmax = min(tmax, max(ty1, ty2)); | |
| return tmax >= tmin; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment