Docstoc

Ray Tracing I Ray-Triangle Intersection

Document Sample
Ray Tracing I Ray-Triangle Intersection Powered By Docstoc
					       Ray Tracing I
Ray-Primitive Intersection (2)
          Ray-Scene Intersection

Intersections with geometric primitives:

•   Sphere
•   Plane
•   Triangle
•   Groups of primitives (scene)
Plane Equation (example)
   Let p1 = (1, -1, -1), p2 = (2, 1, 2) and    Ax + By + Cz + D =0
    p3 = (2, -2, 1).

   The vectors p1 – p2 and p1 – p3 will be
    parallel to the plane (of course, so will
    p3 – p2, p2 – p1, and so on).

   A normal vector to the plane will be
    given by the cross product between p1
    – p2 and p1 – p3, let's assume this
    vector is (n1, n2, n3).

   The plane will then have the equation
    n1x + n2y + n3z + d = 0

   Finding d is simple since you know a
    point on the plane
    (in fact, you know three).
Ray-Plane Intersection

   Ray: P0 and V
      x0,y0,z0 and xv,yv,zv

   Plane: Ax + By + Cz + D =0
      With A2+B2+C2 = 1
      Normal is N = (A,B,C)

   Plug-in:
      A(x0+xvt) + B(y0+yvt) + C(z0+zvt) + D = 0
Ray-Plane Intersection

   A(x0+xvt)+B(y0+yvt)+C(z0+zvt)+D =0

   Ax0+Axvt+By0+Byvt+Cz0+Czvt+D =0

   t = -(Ax0+By0+Cz0+D)/(Axv+Byv+Czv)




    if t < 0, plane intersects behind viewer
          Ray-Scene Intersection

Intersections with geometric primitives:

•   Sphere
•   Plane
•   Triangle
•   Groups of primitives (scene)
Ray-Triangle Intersection       Parametric Method
using barycentric coordinates
Ray-Triangle Intersection
using barycentric coordinates
Advantages of Barycentric Intersection
   Efficient
   Stores no plane equation
   Get the barycentric coordinates for free
      Useful for interpolation, texture mapping
                                          [Möbius, 1827]
Barycentric Coordinates
   P is the barycenter: the single point upon which
    the plane would balance if weights of size α, β,
    and γ are placed on points a, b, and c.
Barycentric Coordinates
   A coordinate system for triangles
      Algebraic viewpoint




     Geometric viewpoint (areas)

   Triangle interior test
Set ray equation equal to barycentric equation
Using Cramer’s rule:
What is the normal at P?
Advantages of Barycentric Intersection
   Efficient
   Stores no plane equation
   Get the barycentric coordinates for free
      Useful for interpolation, texture mapping
          Ray-Scene Intersection

Intersections with geometric primitives:

•   Sphere
•   Plane
•   Triangle
•   Groups of primitives (scene)
Looking from above                My primitives in the scene
                                                      1
                                                      2
                                                      3
                                                      4
                                                      5
eye
                                 for each new ray:
                                 t-min = MAX_DEPTH
                                 (…)
                                 for each primitive prim:
                                      (hit, t) = intersect (prim, ray)
                                      if (hit AND t < t-min)
                                      t-min = t
      MIN_DEPTH      MAX_DEPTH
                                      (…)
                                 return closest-hit
Looking from above                      My primitives in the scene
                                                            1
            t-min = 1000
                                                            2
                                                            3
                                                            4
                                                            5
eye
                                       for each new ray:
                                       t-min = MAX_DEPTH
                                       (…)
                                       for each primitive prim:
                                            (hit, t) = intersect (prim, ray)
                                            if (hit AND t < t-min)
                                            t-min = t
      MIN_DEPTH            MAX_DEPTH
                                            (…)
                                       return closest-hit
Looking from above                      My primitives in the scene

                                                  ?         1
            t-min = 1000
                                                            2
                                                            3
                                                            4
                                                            5
eye
                                       for each new ray:
                                       t-min = MAX_DEPTH
                                       (…)
                                       for each primitive prim:
                                            (hit, t) = intersect (prim, ray)
                                            if (hit AND t < t-min)
                                            t-min = t
      MIN_DEPTH            MAX_DEPTH
                                            (…)
                                       return closest-hit
Looking from above                      My primitives in the scene
                                                            1
            t-min = 1000
                                                  hit       2
                                                            3
                                            t = 700
                                                            4
                                                            5
eye
                                       for each new ray:
                                       t-min = MAX_DEPTH
                                       (…)
                                       for each primitive prim:
                                            (hit, t) = intersect (prim, ray)
                                            if (hit AND t < t-min)
                                            t-min = t
      MIN_DEPTH            MAX_DEPTH
                                            (…)
                                       return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 700
                                                 hit       2
                                                           3
                                           t = 700
                                                           4
                                                           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 700
                                      closest-hit          2
                                                           3
                                                           4
                                                           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 700
                                      closest-hit          2
                                                 ?         3
                                                           4
                                                           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 700
                                      closest-hit          2
                                                           3
                                                hit        4

                                         t = 400           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 400
                                      closest-hit          2
                                                           3
                                                hit        4
                                         t = 400           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 400
                                                           2
                                                           3
                                      closest-hit          4
                                                           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                        My primitives in the scene
                                                              1
            t-min = 400
                                                              2
                                                              3
                                         closest-hit          4
                                      t = 50     hit          5
eye
                                         for each new ray:
                                         t-min = MAX_DEPTH
                                         (…)
                                         for each primitive prim:
                                              (hit, t) = intersect (prim, ray)
                                              if (hit AND t < t-min)
                                              t-min = t
      MIN_DEPTH           MAX_DEPTH
                                              (…)
                                         return closest-hit
Looking from above                       My primitives in the scene
                                                             1
            t-min = 50
                                                             2
                                                             3
                                        closest-hit          4
                                     t = 50     hit          5
eye
                                        for each new ray:
                                        t-min = MAX_DEPTH
                                        (…)
                                        for each primitive prim:
                                             (hit, t) = intersect (prim, ray)
                                             if (hit AND t < t-min)
                                             t-min = t
      MIN_DEPTH          MAX_DEPTH
                                             (…)
                                        return closest-hit
Looking from above                    My primitives in the scene
                                                          1
            t-min = 50
                                                          2
                                                          3
                                                          4
                                     closest-hit          5
eye
                                     for each new ray:
                                     t-min = MAX_DEPTH
                                     (…)
                                     for each primitive prim:
                                          (hit, t) = intersect (prim, ray)
                                          if (hit AND t < t-min)
                                          t-min = t
      MIN_DEPTH          MAX_DEPTH
                                          (…)
                                     return closest-hit
Looking from above                      My primitives in the scene
                                                            1
            t-min = 1000
                                                            2
                                                            3
                                                            4
                                                            5
eye
                                       for each new ray:
                                       t-min = MAX_DEPTH
                                       (…)
                                       for each primitive prim:
                                            (hit, t) = intersect (prim, ray)
                                            if (hit AND t < t-min)
                                            t-min = t
      MIN_DEPTH            MAX_DEPTH
                                            (…)
                                       return closest-hit
Looking from above                      My primitives in the scene

                                                  ?         1
            t-min = 1000
                                                  ?         2
                                                  ?         3
                                                            4
                                                            5
eye
                                       for each new ray:
                                       t-min = MAX_DEPTH
                                       (…)
                                       for each primitive prim:
                                            (hit, t) = intersect (prim, ray)
                                            if (hit AND t < t-min)
                                            t-min = t
      MIN_DEPTH            MAX_DEPTH
                                            (…)
                                       return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 450
                                                           2
                                                           3
                                                hit        4

                                         t = 450           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 450
                                                           2
                                                           3
                                      closest-hit          4
                                                           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 450
                                                           2
                                                           3
                                      closest-hit          4
                                                  ?        5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene
                                                           1
            t-min = 450
                                                           2
                                                           3
                                      closest-hit          4
                                                           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                      My primitives in the scene
                                                            1
            t-min = 1000
                                                            2
                                                            3
                                                            4
                                                            5
eye
                                       for each new ray:
                                       t-min = MAX_DEPTH
                                       (…)
                                       for each primitive prim:
                                            (hit, t) = intersect (prim, ray)
                                            if (hit AND t < t-min)
                                            t-min = t
      MIN_DEPTH            MAX_DEPTH
                                            (…)
                                       return closest-hit
Looking from above                     My primitives in the scene

            t-min = 200               closest-hit          1
                                                           2
                                                           3
                                                           4
                                                           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene

            t-min = 200               closest-hit          1
                                                           2
                                                hit        3
                                                           4
                                          t = 600
                                                           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene

            t-min = 200               closest-hit          1
                                                           2
                                                           3
                                                 ?         4
                                                 ?         5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit
Looking from above                     My primitives in the scene

            t-min = 200               closest-hit          1
                                                           2
                                                           3
                                                           4
                                                           5
eye
                                      for each new ray:
                                      t-min = MAX_DEPTH
                                      (…)
                                      for each primitive prim:
                                           (hit, t) = intersect (prim, ray)
                                           if (hit AND t < t-min)
                                           t-min = t
      MIN_DEPTH           MAX_DEPTH
                                           (…)
                                      return closest-hit

				
DOCUMENT INFO