Unformatted text preview:

University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don FussellRay TracingUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 2ReadingRequired:Watt, sections 1.3-1.4, 12.1-12.5.1.T. Whitted. An improved illumination model for shadeddisplay. Communications of the ACM 23(6), 343-349,1980. [In the reader.]Further reading:A. Glassner. An Introduction to Ray Tracing. AcademicPress, 1989. [In the lab.]K. Turkowski, “Properties of Surface NormalTransformations,” Graphics Gems, 1990, pp. 539-547. [Inthe reader.]University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 3Geometric opticsModern theories of light treat it as both a wave anda particle.We will take a combined and somewhat simplerview of light – the view of geometric optics.Here are the rules of geometric optics:Light is a flow of photons with wavelengths. We'll callthese flows “light rays.”Light rays travel in straight lines in free space.Light rays do not interfere with each other as they cross.Light rays obey the laws of reflection and refraction.Light rays travel form the light sources to the eye, butthe physics is invariant under path reversal (reciprocity).University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 4Synthetic pinhole cameraThe most common imaging model in graphics is the synthetic pinholecamera: light rays are collected through an infinitesimally small holeand recorded on an image plane.For convenience, the image plane is usually placed in front of thecamera, giving a non-inverted 2D projection (image).Viewing rays emanate from the center of projection (COP) at thecenter of the lens (or pinhole).The image of an object point P is at the intersection of the viewing raythrough P and the image plane.University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 5Eye vs. light ray tracingWhere does light begin?At the light: light ray tracing (a.k.a., forward ray tracing or photontracing)At the eye: eye ray tracing (a.k.a., backward ray tracing)We will generally follow rays from the eye into the scene.University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 6Precursors to ray tracingLocal illuminationCast one eye ray,then shade according to lightAppel (1968)Cast one eye ray + one ray to lightUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 7Whitted ray-tracing algorithmIn 1980, Turner Whitted introduced ray tracing to the graphicscommunity.Combines eye ray tracing + rays to lightRecursively traces raysAlgorithm:1. For each pixel, trace a primary ray in direction V to the first visiblesurface.2. For each intersection, trace secondary rays:Shadow rays in directions Li to light sourcesReflected ray in direction R.Refracted ray or transmitted ray in direction T.University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 8Whitted algorithm (cont'd)Let's look at this in stages:University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 9ShadingA ray is defined by an origin P and a unit direction d and isparameterized by t:P + tdLet I(P, d) be the intensity seen along that ray. Then:I(P, d) = Idirect + Ireflected + ItransmittedwhereIdirect is computed from the Phong modelIreflected = kr I (Q, R)Itransmitted = ktI (Q, T)Typically, we set kr = ks and kt = 1 – ks .University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 10Reflection and transmissionLaw of reflection:θi = θrSnell's law of refraction:ηi sinθI = ηt sin θtwhere ηi , ηt are indices of refraction.University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 11Total Internal ReflectionThe equation for the angle of refraction can be computedfrom Snell's law:What happens when ηi > ηt?When θt is exactly 90°, we say that θI has achieved the“critical angle” θc .For θI > θc , no rays are transmitted, and only reflectionoccurs, a phenomenon known as “total internal reflection”or TIR.University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 12Error in Watt!!In order to compute the refracted direction, it is useful tocompute the cosine of the angle of refraction in terms of theincident angle and the ratio of the indices of refraction.On page 24 of Watt, he develops a formula for computingthis cosine. Notationally, he uses µ instead of η for theindex of refraction in the text, but uses η in Figure 1.16(!?),and the angle of incidence is φ and the angle of refraction isθ.Unfortunately, he makes a grave error in computing cosθ.He also has some errors in the figures on the same page. Consult the errata for important corrections!University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 13Ray-tracing pseudocodeWe build a ray traced image by casting raysthrough each of the pixels.function traceImage (scene):for each pixel (i,j) in image S = pixelToWorld(i,j) P = COP d = (S - P)/|| S – P|| I(i,j) = traceRay(scene, P, d)end forend functionUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 14Ray-tracing pseudocode, cont’dfunction traceRay(scene, P, d):(t, N, mtrl) ← scene.intersect (P, d)Q  ray (P, d) evaluated at tI = shade(q, N, mtrl, scene)R = reflectDirection(N, -d)I ← I + mtrl.kr ∗ traceRay(scene, Q, R)if ray is entering object then n_i = index_of_air n_t = mtrl.indexelse n_i = mtrl.index n_t = index_of_airif (mtrl.k_t > 0 and notTIR (n_i, n_t, N, -d)) then T = refractDirection (n_i, n_t, N, -d) I ← I + mtrl.kt ∗ traceRay(scene, Q, T)end ifreturn Iend functionUniversity of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 15Terminating recursionQ: How do you bottom out of recursive raytracing?Possibilities:University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell 16Shading pseudocodeNext, we need to calculate the color returned bythe shade function.function shade(mtrl, scene, Q, N, d):I ← mtrl.ke + mtrl. ka * scene->Iafor each light source λ do: atten = λ -> distanceAttenuation( Q ) * λ -> shadowAttenuation( scene, Q ) I ← I + atten*(diffuse term + spec term)end forreturn Iend functionUniversity of Texas at Austin


View Full Document

UT CS 384G - Ray Tracing

Documents in this Course
Shading

Shading

27 pages

Shading

Shading

27 pages

Load more
Download Ray Tracing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Ray Tracing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Ray Tracing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?