Ray Tracing Fall, 2009. Introduction Simple idea Forward Mapping Natural phenomenon infinite...

Preview:

Citation preview

Ray Tracing

Fall, 2009

Introduction

Simple idea Forward Mapping Natural phenomenon

• infinite number of rays from light source to object to viewer

Backward Mapping Ray Tracing• finite number of rays from viewer through each sample to object

to light source (or other object)

Rendering with Ray Tracing

Ray Tracing Algorithm Generate primary (‘eye’) ray

• ray goes out from eye through a pixel center (or any other sample point on image plane)

Find closest object along ray path• find first intersection between ray and an object in scene

Compute light sample • use illumination model to determine direct contribution from

light sources for greater accuracy

• recursively generate secondary rays at equal

Raytracing versus scan conversion

Raytracing versus scan conversion scan conversion

• After meshing and projection

• 3D 2D Image

• Based on transforming geometry

• for each triangle in scene

Raytracing• 3D Image

• Geometric reasoning about light rays

• for each sample in pixel image…

Ray Tracing: Global Illumination Effects

Raytracing

Overview Eye, view plane section, and scene Launch ray from eye through pixel (Generating Rays) see what it hits (Ray-Scene Intersection) Compute color and fill-in the pixel (Computing light sample)

Generating Rays (1/2)

Ray equation

Through eye at t = 0 At pixel center at t = 1

R(t) = E + td

E

E + td

Ray-Scene Intersection

Ray-Scene Intersection Intersections with geometric primitives

• Sphere

• Triangle

• Groups of primitives (scene)

Acceleration techniques• Bounding volume hierarchies

• Spatial partitions– Uniform grids– Octrees– BSP trees

Ray-Sphere Intersection

Ray-Sphere Intersection

Ray-Sphere Intersection

Need normal vector at intersection for lighting calculations

Ray-Triangle Intersection

Ray-Triangle Intersection First, intersect ray with plane Then, check if point is inside triangle

Ray-Triangle Intersection

intersect ray with plane

Ray-Triangle Intersection

Check if point is inside triangle algebraically

Other Ray-Primitive Intersections

Cone, cylinder, ellipsoid: Similar to sphere

Box Intersect 3 front-facing planes, return closest

Convex polygon Same as triangle (check point-in-polygon algebraically)

Concave polygon Same plane intersection More complex point-in-polygon test

Ray-Scene Intersection

Find intersection with front-most primitive in group

Bounding Volumes

Check for intersection with simple shape first If ray doesn’t intersect bounding volume, then it doesn’t

intersect its contents If found another hit closer than hit with bounding box, then

can skip checking contents of bounding box

Bounding Volume Hierarchies

Use hierarchy to accelerate ray intersections Intersect node contents only if hit bounding volume

Computing light sample

Local Illumination Ray Casting

Computing light sample

Recursive Ray Tracing Shadows and direct lighting Reflection and refraction Antialiasing, motion blur, soft shadows, and depth of field

Shadow Rays

Detect shadow by rays to light source

Shadow Rays

Test for occluder No occluder, shade normally ( e.g. Phong model ) Yes occluder, skip light ( don’t skip ambient )

Reflection Ray

Recursive shading Ray bounces off object Treat bounce rays (mostly) like eye rays Shade bounce ray and return color

• Shadow rays

• Recursive reflections

Add color to shading at original point• Specular or separate reflection coefficient

V B

S

Refracted Ray

Transparent materials bend light Snell’s Law

“Distributed” Raytracing

Send multiple rays through each pixel

Average results together Jittering trades aliasing for noise Use multiple rays for reflection and refraction

How many rays???

“Distributed” Raytracing : Soft Shadows

Soft shadows result from non-point lights Some part of light visible, some other part occluded

Area Light

Occluder

“Distributed” Raytracing : Soft Shadows

Distribute shadow rays over light surface

Soft Shadows

“Distributed” Raytracing : Glossy Reflection

multiple reflection rays

polished surfaceθθ

Justin Legakis

“Distributed” Raytracing : Glossy Translucency

Jittering the rays about the actual transmission angle produces a blurred effect

N

I

T

I

Bound of jittered reflection rays

“Distributed” Raytracing : Motion Blur

Distribute rays over time More when we talk about animation...

Pinhole camera – everything in focus. Camera with lens – utilized depth of field

“Distributed” Raytracing : Depth of Field

Image Plane Image Plane Focal Plane

Pinhole Camera Camera with lens

“Distributed” Raytracing : Depth of Field (DoF)

Distribute rays over a lens assembly multiple rays per pixel

Depth of Field

multiple rays per pixel

Justin Legakisfocal lengthfilm

Depth of Field

Bidirectional Ray tracing

Created by H. Wann Jensen

caustic

Bidirectional Ray tracing

Caustic - (Concentrated) specular reflection/refraction onto a diffuse surface

Standard ray tracing cannot handle caustics caustic

Created by H. Wann Jensen

Examples: POV-ray

created using POV-ray, http://www.povray.org/

POV-ray

created using POV-ray, http://www.povray.org/

POV-ray

created using POV-ray, http://www.povray.org/

POV-ray

created using POV-ray, http://www.povray.org/

Summary

Writing a simple ray casting renderer is easy Generate rays Intersection tests Lighting calculations

Recursive Ray Tracing Shadows and direct lighting Reflection and refraction Antialiasing, motion blur, soft shadows, and depth of field

Bidirectional Ray tracing Caustic : specular reflection/refraction onto a diffuse surface Standard ray tracing cannot handle caustics

Recommended