# Ray Tracing I Ray-Triangle Intersection

Document Sample

```					       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)

 ( N  P0  D)
t        
N V
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
c

a
b
Ray-Triangle Intersection
using barycentric coordinates
c

P(t)
a

V                     b
P0
   Efficient
   Stores no plane equation
 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.
c

α,β,γ 

P

a
b
Barycentric Coordinates
   A coordinate system for triangles
c
 Algebraic viewpoint

P  αa  βb  γc               α,β,γ 
α β  γ 1
Ab        Aa
 Geometric viewpoint (areas)
Ac
   Triangle interior test          a
b

            T,E 2 ,V    
     1                
  E ,E , V  E1,T, V     
t    1  2                
             E1,E 2 ,T
             
                   c
α  1 β  γ
                              
P  P0  tV                              Np
                                          P t 
Np  αNa  βNb  γNc
a
                     b
V
P0
Pα, β, γ   αa  βb  γc

α β  γ 1
c   α  1 β  γ
α,β,γ 
Pβ, γ   1  α  γ a  βb  γc

P

a
b
Set ray equation equal to barycentric equation

Pt   P β ,  

P0  tV  1  α  γ a  βb  γc                  c

P0  tV  a   b  a   c  a

P t 

a
                       b
V

P0

P0  tV  a   b  a   c  a

tV   a  b   a  c  a  P0
c
β
              
  
a  b, a  c, V    a  P0
t 
 
P t 

a
                 b
V

P0
β
                
  
a  b, a  c, V    a  P0
t 
                    c
E1  a  b
E2  a  c
T  a  P0
P t 

                  a
      
  
E1,E2V    T

V
b

t 
          P0
Using Cramer’s rule:


            T,E 2 ,V      
     1                       c
  E ,E , V  E1,T, V       
t    1  2                  
            

E1,E 2 ,T     


P t 

a
                b
V

P0

            T,E 2 ,V                       E1  a  b
     1                
  E ,E , V  E1,T, V                        E2  a  c
t    1  2                
             E1,E 2 ,T
             
                   T  a  P0
                            
Tx    E2 x     Vx   a x  P0 x a x  c x   Vx
                            
Ty    E2 y     Vy   a y  P0 y a y  c y   Vy
                                                  
T,E2 ,V        Tz    E2 z     Vz   a z  P0 z a z  c z   Vz
                                                       
E1,E2 ,V    E1x      E2 x     Vx   a x  bx a x  c x     Vx
                          
E1 y     E2 y     Vy   a y  by a y  c y     Vy
                          
E1z   E2 z     Vz   a z  bz a z  c z     Vz

            T,E 2 ,V                       E1  a  b
     1                
  E ,E , V  E1,T, V                        E2  a  c
t    1  2                
             E1,E 2 ,T
             
                   T  a  P0
                            
E1x    Tx      Vx    a x  bx a x  P0 x   Vx
                            
E1 y   Ty      Vy    a y  by a y  P0 y   Vy
                                                  
E1,T,V         E1z    Tz      Vz    a z  bz a z  P0 z   Vz
                                                       
E1,E2 ,V    E1x       E2 x    Vx    a x  bx a x  cx     Vx
                         
E1 y      E2 y    Vy    a y  by a y  c y    Vy
                          
E1z    E2 z    Vz    a z  bz a z  cz     Vz
if     1.0 and   0.0 and   0.0
then P is inside triangle
c

P t 

a
                    b
V

P0
if     1.0 and   0.0 and   0.0
then P is inside triangle
at position...                                c

P  P0  tV

            T,E 2 ,V    
                            P t 
     1
  E ,E , V  E1,T, V
               
t    1  2                            a
             E1,E 2 ,T
             
                        b
V

P0

            T,E 2 ,V                           E1  a  b
     1                 
  E ,E , V  E1,T, V                            E2  a  c
t    1  2                 
             E1,E 2 ,T
              
                     T  a  P0

E1x    E2 x       Tx  a x  bx a x  c x a x  P0 x
E1 y   E2 y       Ty  a y  by a y  c y a y  P0 y
E1,E2 ,T     E1z    E2 z       Tz  a z  bz a z  c z a z  P0 z
t                                                        
E1,E2 , V   E1x     E2 x       Vx      a x  bx a x  c x Vx
                          
E1 y   E2 y       Vy      a y  by a y  c y V y
                          
E1z    E2 z       Vz      a z  bz a z  c z Vz
What is the normal at P?


            T,E 2 ,V    
     1                
  E1,T, V                            c
  E ,E , V
t    1  2                
             E1,E 2 ,T
             

α  1 β  γ                                
Np
                                             P t 
Np  αNa  βNb  γNc
a
                     b
V

P0
   Efficient
   Stores no plane equation
 Useful for interpolation, texture mapping
a

b   c

            T,E 2 ,V    
     1                
  E ,E , V  E1,T, V     
t    1  2                
             E1,E 2 ,T
             
                   c
α  1 β  γ
                              
P  P0  tV                              Np
                                          P t 
Np  αNa  βNb  γNc
a
                     b
V
P0
c

c

a
                b
V
a
P0                               b
V

P0
c

c

a
                    b
V
a
P0                                   b
V

P0
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
Shared By:
Categories:
Tags:
Stats:
 views: 8 posted: 1/28/2013 language: English pages: 54
How are you planning on using Docstoc?