CSE168 Notes 2, intersections

 Raytracing 1: Intersections

different type of rays need different information, shadow rays intersection / no intersection. primary rays: point of intersection materials, normal, text coord .. etc

Ray-Sphere Intersection

 Ray = \vec{P} = \vec{P}_0 + \vec{P}_1 t
 Sphere = (\vec{P} - \vec{C}) \cdot (\vec{P} - \vec{C}) - r^2 = 0

Substitute:

 Sphere = (\vec{P}_0 + \vec{P}_1 t - \vec{C}) \cdot (\vec{P}_0 + \vec{P}_1 t - \vec{C}) - r^2 = 0

Simplify

Substitute:

 Sphere = t^2 ( \vec{P}_1 \cdot \vec{P}_1) + 2 t \vec{P}_1 \cdot  (\vec{P}_0 - \vec{C}) + (\vec{P}_0 - \vec{C}) \cdot  (\vec{P}_0 - \vec{C}) - r^2 = 0

quadratic equation for t

  • 2 real positive roots: pick smaller root
  • both roots same: tangent to sphere
  • one positive, one negative root: ray origin inside sphere ( pic + root)
  • complex roots: not intersection (check discriminant of equation first)

Intersection point

substitute t back to the ray equation. surface normal at point of intersection:

 \vec{N} = \frac{\vec{P} - \vec{C}}{|\vec{P} - \vec{C}|}

Ray-Triangle Intersection

  • one approach: Ray-Plane intersection, then check if inside triangle
 plane = \vec{P} \cdot \vec{n} - \vec{A} \cdot \vec{n} = 0

Combine with ray equation

 t =  \frac { \vec{A} \cdot \vec{n} - \vec{P}_0 \cdot \vec{n} }{ \vec{P}_1 \cdot \vec{n}}
  • still need to find intersection point inside the polygon
  • Ray intersection inside triangle odd amount in, even out
  • we find parametrically [barycentric coordinates]

Other primitives: cones, cylinders, ellipsoids

Boxes (useful for bounding boxes)

Many more primitives

Ray-Tracing Transformed objects

We have ray-sphere test but want to test ellipsoid

  • apply inverse transform to ray, use ray-sphere
  • allows instancing
  • general 4×4 transform M (matrix stacks)
  • apply inverse transform of M to ray
  • do standard ray-surface intersection as modified
  • transform intersection back to actual coordinates

Leave a Reply

Your email address will not be published. Required fields are marked *