Skip to content

Instantly share code, notes, and snippets.

@apriori
Created September 13, 2013 13:46
Show Gist options
  • Save apriori/6550937 to your computer and use it in GitHub Desktop.
Save apriori/6550937 to your computer and use it in GitHub Desktop.
intersectDist :: Exp Ray -> Exp Sphere -> Exp SphereIntersect
intersectDist r s =
let
v = (center s) -. (start r)
a = dot v (dir r)
in
(a <* 0) ? (
lift $ (constant False, s, constant (-1.0)),
let
b2 = dot v v - a * a
r2 = (radius s) * (radius s)
in
(b2 >* r2) ? (lift $ (cfalse, s, constant (-1.0)),
let
c = sqrt(r2 - b2)
near = a - c
far = a + c
distance = (near <* 0) ? (far, near)
in
lift $ (constant True, s, distance))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment