p - nptel

Ray Tracing
Set up
3D Viewing Interface (Revisit)
V
Y
Eye
U
N
X
Z
World Coordinate System
(WCS)
Viewing Coordinate
System (VCS)
Ray Tracing
Set up
3D Viewing Interface (Revisit)
Eye
View Plane, n=0
Front Plane
n=F
Back Plane
n=B
Ray Tracing
Set up
3D Viewing Interface (Revisit)
u
v
n
p
t=1
p (pu,pv,pn)
e
p*
p*(u*,v*)
t=t’
e
t=0
Parametrically r(t) = e(1-t)+p.t
Ray Tracing
Set up
3D Viewing Interface (Revisit)
Conversion from one coordinate system to another
• (a,b,c) in VCS
• (x,y,z) in WCS
p  x y z   a b c  M  r
a b c   ( p  r ) M 1
u  u x

 ( p  r ) MT
Where M  v   v x
  
n  n x
uy
vy
ny
uz 

vz 
nz 
Ray Tracing
Set up
Steps
1. Define the view reference point (VRP) = r
2. Obtain M defining u, v, n
3. Define the position of eye (in VCS)
e = ( eu, ev, en) typically ( 0, 0, -E )
corresponding point in WCS will be
eye = ( 0, 0, -E ) M + r
4. Define the window and the pixel location.
Ray Tracing
Set up
rows : 0 to MAXROW
cols : 0 to MAXCOL
v
Wt
(i,j)th pixel : (ui, vj, 0)
n
Wb
Wl
e ( 0 ,0 , -E)
u
Wr
ui = Wl + i u
vj = Wt – j v
u = ( Wr – Wl ) / MAXCOL
v = ( Wt – Wb ) / MAXROW
Ray Tracing
Set up
5. Parametric equation of ray
Pi,j(t) = eye + dirij t
eye = ( 0 , 0 , -E ) M + r
dirij = ( ( ui , vj , 0 ) – e) M
= ( ui , vj , E ) M
Pij(t) = eye + dirij t
R(t) = Ro + Rdt
Ray Tracing
Set up
•
•
•
•
Find intersection with object (ri)
Find the normal at ri as rn
Find intensity at I at the point
(Illumination model)
Find the pixel-color
Ray Tracing
Transforming Objects
Ray : R(t) = s + c t
Objects : sphere, box, cone etc.
We assume the objects to be normalized (generic) so that
the ray-object intersection test is easier
e.g. Sphere is x2 + y2 + z2 = 1
Ray Tracing
Transforming Objects
In a hierarchical description of a scene various modeling
transformations (affine) may be applied to the normalized
primitives to get variety in the scene
Can this be handled using simple ray object intersections ?
Ray Tracing
Transforming Objects
T:M,d
q’
q
T-1 : M -1, -d
Let the sphere be transformed under an affine
transformation T : M, d
i.e.
q = q’M + d
Ray Tracing
Transforming Objects
p
p’
s’ + c’ t
s’ + c’t = ( s + ct ) M -1
s’ = ( s - d ) M-1
c’ = c M-1
s+ct
Ray Tracing
Transforming Objects
For rendering we also require the normal at the point of
intersection of the transformed primitive
Can the normal be computed using the old normal and the
transformation (T) ?
n
?
n’
Ray Tracing
Transforming Objects
Suppose pa and pb be two points arbitrarily close on the
generic object
Then
( pa – pb ).n = 0
( pa – pb ) n T = 0
After applying the transformation T: M, d to pa and pb
( pa – pb ) M (n’)T = 0
where n’ is the normal of the transformed object
Ray Tracing
Transforming Objects
Solve for n’
( pa – pb ) M (n’)T = 0
Let N be the transformation which gets applied to the
normal of the generic primitive
Then
( pa – pb ) M (nN)T = 0
( pa – pb ) MNT nT = 0
This holds true when NT = M-1 i.e. N = (M-1)T
Ray Tracing
Review
Basic ray tracing (one level): ray casting
Algorithm:
For each pixel shoot a ray from eye (COP)
Compute ray-object(s) intersection
Obtain the closest intersection point (p)
Compute normal at p
Compute illumination (intensity)
Set up:
Obtain ray in WCS for intersection using
transformations
Transformation of objects:
Equivalent transformation for the ray
Ray Tracing
Recursive Ray Tracing
D
T2
R2
B
Eye
R1
eye-ray
T1
C
A
View Plane
F
E
Ray Tracing
Recursive Ray Tracing
Eye
C
T1
R1
D
R2
T2
Ray Tracing
Recursive Ray Tracing
Different Rays
Eye ray (primary ray)
Reflected ray
Transmitted ray
Shadow ray
(secondary rays)
Ray Tracing
Recursive Ray Tracing
Reflected Ray
Recall Reflection Vector
N
N
L
qi qr
R
L
R
2(L  N )N
-L
R  2(L  N )N  L
Ray Tracing
Recursive Ray Tracing
Refracted Ray
Snell’s Law
N
I
qi
sinθ i ηt

sinθ t ηi
qt T
Ray Tracing
Recursive Ray Tracing
Refracted Ray
Snell’s Law
I
qi (cos θi )N
M
qt T
I  (cos θi )N
sin θi
T  (sin θt )M  (cos θt )N
sin θt (I  (cos θi )N )
T 
 (cos θt )N
sin θi
η
T  i (I  (cos θi )N )  (cos θt )N
ηt
M
N
Ray Tracing
Recursive Ray Tracing
Eye
Obj 3
L2
L1
Obj 1
Obj 2
Obj 1
Ray Tracing
Recursive Ray Tracing
Eye
Eye
L1
Obj 3
L2
L1
Obj 1
Obj 2
L2
Obj 1
T
Obj 2
R
Obj 3
Ray Tracing
Recursive Ray Tracing
Eye
Eye
L1
Obj 3
L2
L1
L2
Obj 1
L1
Obj 1
L2
Obj 2
R
T
L2
Obj 3
Obj 2
R
L1
T
R
Ray Tracing
Recursive Ray Tracing
When to stop ?
When ray leaves the scene
When the contribution to the overall intensity is small
Ray Tracing
Recursive Ray Tracing
Phong Illumination Model
Itotal  ambient reflection  diffuse reflection  specular reflection
 k aIa  kd Il cos θ  ks Il cos n α
 k a I a  k d I l ( L  N )  k s I l ( R  V )n
m
 k aIa   k d Ii (Li  N )  ks Ii (Ri  V )n
i 1
Ray Tracing
Recursive Ray Tracing
Illumination
When in shadow (single light source)
Itotal  ambient reflection
 k aI a
Ray Tracing
Recursive Ray Tracing
Illumination
With reflection and transmission rays
Itotal (P )  Ilocal (P)  k rg I(Pr )  ktg (Pt )
Global Illumination
Ray Tracing
Recursive Ray Tracing
T Whitted 1980
Ray Tracing
Recursive Ray Tracing
Other Example
Ray Tracing
Recursive Ray Tracing
Other features
• Ray tracing is an image based method (pixelization)
• Sampling
“aliasing”
Jagginess
Moire patterns
• Anti-aliasing
Ray Tracing
Recursive Ray Tracing
Anti-alising
• Supersampling
• More number of rays per pixel
• Average the result