Loading in 5 sec....

Advanced Computer Graphics Lecture 2: Ray TracingPowerPoint Presentation

Advanced Computer Graphics Lecture 2: Ray Tracing

- 74 Views
- Uploaded on
- Presentation posted in: General

Advanced Computer Graphics Lecture 2: Ray Tracing

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Advanced Computer GraphicsLecture 2: Ray Tracing

David Luebke

cs551dl@cs.virginia.edu

http://www.cs.virginia.edu/~cs551dl

David Luebke6/10/2014

- Idea dates back to Descartes (1637)
- In graphics: Turner Whitted (1980)
- Used recursive ray tracing as general framework for:
- Hidden surface problem
- Shadow computation
- Reflection/refraction

- Much work in the 80’s, then fell into academic disfavor (Turner’s old joke)

- Used recursive ray tracing as general framework for:

David Luebke6/10/2014

David Luebke6/10/2014

Pixel

ImagePlane

David Luebke6/10/2014

“Direct” Ray To Eye

David Luebke6/10/2014

“Indirect” Ray To Eye

David Luebke6/10/2014

- Physically, we’re interested in path of light rays from light source to eye.
- In practice, we trace rays backwards from eye to source (Why?)

David Luebke6/10/2014

- Physically, we’re interested in path of light rays from light source to eye.
- In practice, we trace rays backwards from eye to source (Why?)
- Computational efficiency: we want the finite subset of rays that leave source, bounce around, and pass through eye
- Can’t predict where a ray will go, so start with rays we know reach eye

David Luebke6/10/2014

- Function TraceRay() Recursively trace ray Rand return resulting color C
- IfRintersects any objects then
- Find nearest object O
- Find local color contribution
- Spawn reflected and transmitted rays, using TraceRay() to find resulting colors
- Combine colors; return result

- else
- return background color

- IfRintersects any objects then

David Luebke6/10/2014

Object allObs[];

Color image[];

RayTraceScene()

allObs = initObjects();

for (Yall rows in image)

for (X all pixels in row)

Ray R = calcPrimaryRay(X,Y);

image[X,Y] = TraceRay(R);display(image);

David Luebke6/10/2014

Color TraceRay(Ray R)

ifrayHitsObjects(R) then

Color localC, reflectC, refractC;

Object O = findNearestObject(R);

localC = shade(O,R);

Ray reflectedRay = calcReflect(O,R)

Ray refractedRay = calcRefract(O,R)

reflectC = TraceRay(reflectedRay);

refractC = TraceRay(refractedRay);

return localC reflectC refractC

else returnbackgroundColor

David Luebke6/10/2014

Color TraceRay(Ray R)

ifrayHitsObjects(R) then

Color localC, reflectC, refractC;

Object O = findNearestObject(R);

localC = shade(O,R);

Ray reflectedRay = calcReflect(O,R)

Ray refractedRay = calcRefract(O,R)

reflectC = TraceRay(reflectedRay);

refractC = TraceRay(refractedRay);

return localC reflectC refractC

else returnbackgroundColor

David Luebke6/10/2014

- Given a ray and a list of objects, what (if any) objects does the ray intersect?
- Query: Does ray R intersect object O?
- How to represent ray?
- What kind of object?
- Sphere
- Polygon
- Box
- General quadric

David Luebke6/10/2014

R = O+ tD

O

t < 0

t = 1

t > 1

D

- How might we represent rays?
- We represent a ray parametrically:
- A starting point O
- A direction vector D
- A scalar t

- Why?

David Luebke6/10/2014

- Ray R = O + tD
x = Ox + t * Dx

y = Oy + t * Dy

z = Oz + t * Dz

- Sphere at (l, m, n) of radius r is:
(x - l)2 + (y - m)2 + (z - n)2 = r 2

- Substitute for x,y,z and solve for t…

David Luebke6/10/2014

- Works out as a quadratic equation:
at2 + bt + c = 0

where

a = Dx2 + Dy2 + Dz2

b =2Dx(Ox - l) + 2Dy(Oy - m) + 2Dz(Oz - n)

c = l2 + m2 + n2 + Ox2 + Oy2 + Oz2 - 2(l Ox + m Oy + n Oz + r2)

David Luebke6/10/2014

- If solving for t gives no real roots: ray does not intersect sphere
- If solving gives 1 real root r, ray grazes sphere where t = r
- If solving gives 2 real roots (r1, r2), ray intersects sphere at t = r1& t = r2
- Ignore negative values
- Smallest value is first intersection

David Luebke6/10/2014

- Find intersection point Pi = (xi, yi, zi) by plugging t back into ray equation
- Find normal at intersection point by subtracting sphere center from Pi and normalizing:
(When might we need the normal? When not?)

David Luebke6/10/2014

- Polygons are the most common model representation (Why?)
- Basic approach:
- Find plane equation of polygon
- Find intersection of ray and plane
- Does polygon contain intersection point?

David Luebke6/10/2014

y

N

P2

P1

d

x

- Find plane equation of polygon:ax + by + cz + d = 0
- How?
N = [a, b, c]

d = N P1

(How to find N ?)

David Luebke6/10/2014

- Find intersection of ray and plane:
t = -(aOx + bOy + cOz + d) / (aDx + bDy + cDz)

- Does poly contain intersection point Pi ?
- Book’s algorithm:
- Draw line from Pi to each polygon vertex
- Measure angles between lines (how?)
- If sum of angles between lines is 360°, polygon contains Pi

- Slow — better algorithms available

- Book’s algorithm:

David Luebke6/10/2014

- Often want to find whether a ray hits an axis-aligned box (Why?)
- One way:
- Intersect ray with pairs of parallel planes that form box
- If intervals of intersection overlap, the ray intersects the volume.

David Luebke6/10/2014