# Ray Casting _amp; Ray Tracing by yurtgc548

VIEWS: 5 PAGES: 42

• pg 1
```									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 sam
ple 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 + td
E
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
 Reflection and refraction
 Antialiasing, motion blur, soft shadows, and depth of field

 Detect shadow by rays to light source

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

 Ray bounces off object
 Treat bounce rays (mostly) like eye rays
 Shade bounce ray and return color
• Recursive reflections
• 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 result from non-point lights
 Some part of light visible, some other part occluded

Area Light

Occluder
“Distributed” Raytracing

 Distribute shadow rays over light surface
“Distributed” Raytracing
: Glossy Reflection

 multiple reflection rays

Justin Legakis

θ   θ   polished surface
“Distributed” Raytracing
: Glossy Translucency
N
 Jittering the rays
I
transmission angle
produces a blurred                           I
effect

T
Bound of jittered
reflection rays
“Distributed” Raytracing
: Motion Blur

 Distribute rays over time
 More when we talk about animation...
“Distributed” Raytracing
: Depth of Field

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

Pinhole Camera                   Camera with lens

Image Plane          Image Plane            Focal Plane
“Distributed” Raytracing
: Depth of Field (DoF)

 Distribute rays over a lens assembly
 multiple rays per pixel
Depth of Field

 multiple rays per pixel

film             focal length      Justin Legakis
Depth of Field
Bidirectional Ray tracing

caustic

Created by H. Wann Jensen
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