ray tracing
DESCRIPTION
Ray Tracing. Ray Tracing. Highly realistic Considerable computation time. Ray Tracing. prp. Ray Tracing. ambient light: k a I a diffuse light: k d (N.L) specular light: k s (H.N) ns specular reflection direction: R = u-(2u.N)N - PowerPoint PPT PresentationTRANSCRIPT
Ray TracingRay Tracing
Ray Tracing
Highly realistic
Considerable computation time
Ray Tracing
prp
Ray Tracing
ambient light: ka Iadiffuse light: kd (N.L)
specular light: ks (H.N)ns
specular reflection direction:
R = u-(2u.N)N
T = [(i/r) cos i - cos r] N - (i/r)L
cos r = √1 - (i/r)2 (1-cos2 i )
T
reflected light
i
incoming ray(viewing direction V = -u)
r
R
L
N
H
u
shadow ray
i
r
Ray Tracing
main() {Select prpfor (each scan line)
for (each pixel in scan line) determine ray from prp through pixel pixel = Trace (ray, 1)
}
Trace (ray, depth) {determine closest intersection of ray with an objectif (object hit) compute normal at intersection return Shade( closest object hit, ray,
intersection, normal, depth)else return background_value
}
Shade ( object, ray, point, normal, depth) {color = ambient termfor (each light) Sray = ray to light from point if (N.L>0)
compute how much light is blocked by opaque andtransparent surfaces, and use to scale diffuse andspecular terms before adding term to color
if (depth < maxdepth) if (object is reflective)
Rray = ray in reflection direction from pointRcolor = Trace (Rray, depth+1)scale Rcolor by specular coeff. and add to color
if (object is transparent)Tray = ray in refraction direction from pointif (total internal reflection does not occur) Tcolor = Trace (Tray, depth+1) scale Tcolor by transmission coeff. and add to
colorreturn color
}
Ray TracingRay equation
P = P0 + s.u
P: any point along the rayP0: initial position vectors: distance of P to P0 u: unit direction vector
Ppix – Pprp
u = ------------------| Ppix – Pprp |
Initially P0 is Ppix or prp.Update P0 and u at each intersection point
on the ray with a surface.
prp
ray path
P0
x
y
z
u
Ppix
Ray Tracing
Ray Tracing
Ray Tracing
Ray Tracing