Raytracing

19
Raytracing Image synthesis using classical optics

description

Raytracing. Image synthesis using classical optics. Raytracing. Create an image by following the paths of rays through a scene “ Backward raytracing": traces rays out of the light sources out into the world - PowerPoint PPT Presentation

Transcript of Raytracing

Page 1: Raytracing

Raytracing

Image synthesis using classical optics

Page 2: Raytracing

RaytracingCreate an image by following the paths

of rays through a scene“Backward raytracing": traces rays out

of the light sources out into the world“Forward raytracing": traces rays out

from the eye (camera) and out into the world and eventually back to the light sources

Page 3: Raytracing
Page 4: Raytracing
Page 5: Raytracing

Forward RaytracingSimplest form (raycasting):

for each pixel on the screen, send a ray out into the world

determine the first surface hit by the ray perform a lighting calculation at that

surface point set the color of the pixel according to the

result of the lighting calculation

Page 6: Raytracing

Raytracing

screen rays from eye

Page 7: Raytracing

RaysA ray is a half-line – it has only one end It can be written

p = o + t*d, t in (0,∞)

p is position (vector)o is the origin (vector)d is direction (vector)t is the parameter

Page 8: Raytracing

Ray Intersection Key computation: intersection of ray with

objects Typically produced by solving an equation:

p = f(t)Say the object is defined by an implicit surface,

g(x,y,z) = 0Then g(f(t)) = 0

Smallest value of t means first intersection

Page 9: Raytracing

Ray Intersection

Page 10: Raytracing

Ray-Sphere Intersection Implicit equation of sphere:

(x-xc)2 + (y-yc)2 + (z-zc)2 – R2 = 0 Or, (p-pc)•(p-pc) – R2 = 0

Say ray is given by p(t) = e + t*d

Then(d • d)t2 + 2d•(e - c)t + (e – c)•(e – c) – R2 = 0

Page 11: Raytracing

Other QuadricsCylinders, ellipsoids, paraboloids,

hyperboloids: all have the property that they are algebraic surfaces of degree 2, aka quadrics

The intersection calculation can be done analytically using the quadratic equation

Page 12: Raytracing

Lighting CalculationSo… we know where the ray hits the

surfaceBut what does the surface look like?Need to compute lighting at the point of

intersection

Page 13: Raytracing

Local Lighting CalculationCan use 3-term lighting calculation

local illumination

Raytracing allows us to do global illumination shadows reflected and refracted light

Page 14: Raytracing

Shadow RaysDecide if a point is in shadow or not

based on new ray intersection testCast ray from intersection point towards

light source If intersection found, point is in shadowOtherwise, not in shadow

Page 15: Raytracing

Raytracing TreeResolving a ray intersection can result in multiple additional rays

Transmitted rays

Ray intersection

Reflected rays

Shadow ray

Page 16: Raytracing

Reflected RaysRecursive call to raycast:

ray’s color is (1-c) times the color computed at the surface, plus c times the color computed by a new ray heading out of the surface in the reflected direction

May cast multiple reflected rays at slightly different directions

Need to terminate the recursion: maximum depth minimum energy carried by the ray

Page 17: Raytracing
Page 18: Raytracing

Accelerating IntersectionsMajority of work in raytracer in

computing intersectionsSimple-minded method: compute

intersections with every object in scene, take smallest parameter

Need to speed this up bounding geometry spatial partitioning

Page 19: Raytracing

Raytracing vs Z-Buffer Initial intersection test is the hard part

Z-buffer still supremeBut, all kinds of effects with same code

transparency, reflection, shadows, caustics in Z-buffer, bizarre stack of methods

"Embarrassingly parallel": well suited to GPU from process viewpoint – but, recursion not possible on cards