Ray Tracing Ray Tracing Chapter 10.11 Chapter 10.11 CAP4730: Computational Structures in Computer Graphics
Dec 31, 2015
Ray TracingRay Tracing
Chapter 10.11Chapter 10.11
CAP4730: Computational Structures in Computer Graphics
OutlineOutline
What is raytracing?What is raytracing? How is raytracing different than How is raytracing different than
what we’ve done before?what we’ve done before? Math behind raytracingMath behind raytracing Uses of raytracingUses of raytracing
Forward MappingForward Mapping
Forward mapping is what we are Forward mapping is what we are used to.used to.
Forward MappingForward Mapping
Take each primitiveTake each primitive Figure out where on the screen it Figure out where on the screen it
should appearshould appear Also known is feed-forwardAlso known is feed-forward
Ray TracingRay Tracing
Ray tracing is the “inverse” of the Ray tracing is the “inverse” of the “forward” mapping we are used to.“forward” mapping we are used to.
Ray TracingRay Tracing
Also known as inverse mapping or feed-Also known as inverse mapping or feed-backwardbackward
Feed-Forward vs.Feed-Forward vs. Feed-Backward Feed-Backward
Pros and Cons of eachPros and Cons of each
Ray-TracingRay-Tracing Attempts to trace the paths of Attempts to trace the paths of
light that contribute to each light that contribute to each pixel that make up a scenepixel that make up a scene
Instead of computing visible Instead of computing visible surfaces, determine surfaces, determine intensity intensity contributionscontributions
Compute Compute global illuminationglobal illumination Allows for:Allows for:
– ReflectionReflection– RefractionRefraction– Atmospheric effectsAtmospheric effects– ShadowsShadows
Results in very realistic scenesResults in very realistic scenes– Used in movies, animations, Used in movies, animations,
cut-scenescut-scenes
Center of Center of ProjectionProjection– Infinite RaysInfinite Rays– Care about ones Care about ones
that pass through that pass through the virtual screenthe virtual screen
– For each pixelFor each pixel Compute ray to a Compute ray to a
pixelpixel For each object in For each object in
the scenethe scene– Compute the Compute the
intersection intersection between ray between ray and objectand object
Find closest Find closest intersectionintersection
Calculate Calculate illuminationillumination
Similar to a Similar to a pinhole camerapinhole camera
for (j=0;j<IMAGE_HEIGHT;j++)for (j=0;j<IMAGE_HEIGHT;j++)
for (i=0;i<IMAGE_WIDTH;i++)for (i=0;i<IMAGE_WIDTH;i++)
result=CheckForIntersection(i,j)result=CheckForIntersection(i,j)
SetPixel(i,j,result);SetPixel(i,j,result);
CheckForIntersection(i,j)CheckForIntersection(i,j)
ray = vector from eye through pixel on ray = vector from eye through pixel on display planedisplay plane
if (DetermineIntersection(ray, color))if (DetermineIntersection(ray, color))
return color;return color;
Computational Cost of Ray Computational Cost of Ray TracingTracing
Let’s compute a formula for how much Let’s compute a formula for how much work we have to do:work we have to do:
O(i*j*intersection tests)O(i*j*intersection tests) What is an intersection test?What is an intersection test? What is the cost of an intersection test?What is the cost of an intersection test? We test the ray going from the eye We test the ray going from the eye
through each pixel for an intersection through each pixel for an intersection with with anyany object. object.
How are objects specified?How are objects specified?
Ray Triangle IntersectionRay Triangle Intersection
Ray is specified as a vector and a starting Ray is specified as a vector and a starting position (camera)position (camera)
There are many different methods (search the There are many different methods (search the web) to do ray - triangle intersectionweb) to do ray - triangle intersection
One solution: Intersect with the plane of the One solution: Intersect with the plane of the triangle. Determine if the intersection point is triangle. Determine if the intersection point is within the trianglewithin the triangle
Defining objectsDefining objects
We don’t have to use triangles We don’t have to use triangles exclusively.exclusively.
Let’s think about other objects and the Let’s think about other objects and the different intersections. How would we different intersections. How would we specify:specify:– SpheresSpheres– CylindersCylinders– CubesCubes– Other base geometric objectsOther base geometric objects
Ray IntersectionsRay Intersections
http://www.swin.edu.au/astronomy/pbourke/geometry/sphereline/
Since performance is so closely tied to ray-object intersections, we’d like to speed it up. How can we speed things up?
Break down things into two steps, detecting intersections, and determining location of intersection.
Ray IntersectionsRay Intersections
We are emulating “reality” where light We are emulating “reality” where light reaches our eye.reaches our eye.
We are asking “what is the path of the We are asking “what is the path of the light that reached our eye for that light that reached our eye for that pixel?”pixel?”
Ray Tracing (in the way we know it), Ray Tracing (in the way we know it), was started by Turner Whitted (1980).was started by Turner Whitted (1980).
With ray tracing, we can solve for With ray tracing, we can solve for global illuminationglobal illumination..
Ray Tracing ObservationsRay Tracing Observations
Each pixel must be evaluatedEach pixel must be evaluated Hard for non solid objectsHard for non solid objects No screen space coherenceNo screen space coherence Difficult to do in parallelDifficult to do in parallel Difficult to accelerateDifficult to accelerate
Recursive Ray-TracingRecursive Ray-Tracing How would we compute lighting? How would we compute lighting?
Let’s Let’s reversereverse the light ray that got the light ray that got to our eyeto our eye
Upon intersection, fire ‘secondary Upon intersection, fire ‘secondary rays’rays’
Vector to the light
Refraction RayReflected Ray
Upon IntersectionUpon Intersection
How do we compute each?How do we compute each? Why follow each ray?Why follow each ray?
– Each contributes intensity to the intersection Each contributes intensity to the intersection position!position!
u
N
L, shadow ray
T
Θi
Θr
R
indices of refractionindices of refraction
u
N
L, shadow ray
T
Θi
Θr
NuT ir
ir
r
i
coscosi
r
ir
2
2
cos11cos
NNuuR 2
R
Ray-Surface IntersectionRay-Surface Intersection
RayRay– P=PP=P00 + s*u + s*u
– PP00 - initial point of ray - initial point of ray
– u – unit vectoru – unit vector– u = (pixel – COP)/|(pixel-COP)u = (pixel – COP)/|(pixel-COP)– s – distance along vectors – distance along vector
Recursive Ray-TracingRecursive Ray-Tracing
ShadowsShadows
Vector to the light
Refraction RayReflected Ray
Recursive Ray-TracingRecursive Ray-Tracing
For each ray, we repeat the For each ray, we repeat the processprocess
How many “levels of recursion” How many “levels of recursion” should we do?should we do?
Refraction Ray
Reflected Ray
Vector to the light
RercursionRercursion
How do we compute the refraction vector? How do we compute the refraction vector? What properties would you want to include What properties would you want to include
with an object?with an object?
Refraction Ray
Reflected Ray
Vector to the light
Depth of recursionDepth of recursion Time vs. AccuracyTime vs. Accuracy Tree Data Tree Data
StructureStructure– ray-tracing treeray-tracing tree– pg. 599 in bookpg. 599 in book– How deep is the How deep is the
tree?tree? What are some end What are some end
conditions?conditions? What are some What are some
acceptable end-acceptable end-limits?limits?
LightingLighting
So how do we compute the final color?So how do we compute the final color? We can employ many lighting modelsWe can employ many lighting models
– Phong LightingPhong Lighting– Torrence-SparrowTorrence-Sparrow– BRDF modelsBRDF models
What lighting can it not do?What lighting can it not do?– Caustics (focused light like in water)Caustics (focused light like in water)– specular to specular or diffusespecular to specular or diffuse– diffuse to diffuse or speculardiffuse to diffuse or specular
LightingLighting
We’ll cover lighting much more in depth We’ll cover lighting much more in depth laterlater
For now:For now:– Three termsThree terms
Ambient – global light that exists (hack)Ambient – global light that exists (hack) Diffuse –contribution of a light. Dependent on Diffuse –contribution of a light. Dependent on
light locationlight location Specular – contribution of a light that is wrst Specular – contribution of a light that is wrst
user’s eyeuser’s eye
– L = kL = kaaIIaa + k + kdd(n*L) +k(n*L) +kss(h*N)(h*N)nsns
Ray Tracing Pros and ConsRay Tracing Pros and Cons
ProsPros– TransparencyTransparency– ReflectionsReflections– ShadowsShadows– Complex Complex
Primitives (math Primitives (math equations)equations)
– Easy to writeEasy to write
ConsCons– Hard to accelerateHard to accelerate– Isn’t the complete Isn’t the complete
global illuminationglobal illumination– Very slow per Very slow per
pixel calculation.pixel calculation.
What is slow about Ray What is slow about Ray Tracing?Tracing?
Ray Triangle intersectionsRay Triangle intersections Let’s talk about bounding volumesLet’s talk about bounding volumes Heirarchies?Heirarchies? What are some properties of the What are some properties of the
volumes that determines how “good” a volumes that determines how “good” a bounding volume is?bounding volume is?
Spatial SubdivisionSpatial Subdivision
Divide space into regions
Place objects into different regions
Compute which regions you can “see” from your current position
Only test those objects
Developing a hierarchy of tests
Other TricksOther Tricks
How would we doHow would we do– antialiasingantialiasing– texturingtexturing– transparencytransparency– different material propertiesdifferent material properties
Refraction Ray
Reflected Ray
Vector to the light
Ray TracingRay Tracing
http://graphics.lcs.mit.edu/http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture20/classes/6.837/F98/Lecture20/RayTrace.javaRayTrace.java
POV-Ray (www.povray.org)POV-Ray (www.povray.org)