ray tracing - cs.huji.ac.il
TRANSCRIPT
1
1
Ray Tracing
2
Ray Tracing
Ray Tracing kills two birds with one stone:Solves the Hidden Surface Removal problemEvaluates an improved global illumination model⌧shadows⌧ideal specular reflections⌧ideal specular refractions
Enables direct rendering of a large variety of geometric primitives
Book: A. Glassner, An Introduction to Ray Tracing
2
3
Backward Tracing
4
Reflected, Transmitted and Shadow rays
3
5
The Illumination Model
Remember the local illumination model we saw earlier?
First, let’s add shadows into the model:
( ) ( )1
i i
nr a a att p d i s i
iI I k f I k N L k R V
=
= + ⋅ + ⋅ ∑
( ) ( )[ ]∑=
⋅+⋅+=1i
nisidpattiaar VRkLNkIfSkII
ii
6
Illumination Model (cont’d)
Add in light arriving from the mirror-reflected directionAdd in light arriving from the ideal refracted direction (Snell’s Law)
ss Ik
tt Ik
( ) ( )[ ]ttss
i
nisidpattiaar
IkIk
VRkLNkIfSkIIii
++
⋅+⋅+= ∑=1
4
7
Refraction
8
Refraction Geometry
5
9
And the result is...
10
6
11
12
7
13
The RT AlgorithmFor each pixel (x,y) in the image, generate the corresponding ray in 3D.Image(x,y) := TraceRay(ray)TraceRay(ray)
compute nearest ray-surface intersectionif none found, return background colorcompute direct illuminationcompute illumination arriving from reflected directioncompute illumination arriving from refracted directioncombine illumination components using the shading modelreturn resulting color
14
The RT Algorithm
Direct illumination: test the visibility of each source by shooting a shadow ray towards it. Only sources which are found visible are summed in the shading model.
Reflected/refracted illumination: a recursive call to TraceRay with the reflected/refracted ray as argument.
8
15
The depth of reflection
16
Ray-Surface Intersection
Implicit surfaces:Use a parametric representation for the ray:
Substitute into the implicit equation:
Solve the resulting equation
Examples: plane, sphere
0),,( =zyxf
( )( )( )( )
x x x
y y y
z z z
R t O tDR t O tDR t O tDR t O tD
= += += += +
0),,( =+++ zzyyxx tDOtDOtDOf
9
17
Ray Plane intersectionImplicit Formulation
Find ‘t’ such that f(x,y,z) = 0
zzz
yyy
xxx
tDOtRtDOtRtDOtRtDOtR
+=+=+=+=
)()()()( O
DN
( , , ) 0
( ) ( ) ( )
( ) ( )
x y z
x x x y y y z z z
x x y y z z x x y y z z
x x y y z z
x x y y z z
f x y z N x N y N z dN O tD N O tD N O tD dN D N D N D t d N O N O N O
d N O N O N Ot
N D N D N D
= + + + =
+ + + + + = −
+ + = − + + +
+ + += −
+ +
18
Ray Sphere intersection
Find ‘t’ such that f(x,y,z) = 0( )R t O tD= + O
D2 2 2
2 2 2
( , , ) 1( ) ( ) ( ) 1
...x x y y z z
f x y z x y zO tD O tD O tD
= + + −
+ + + + + =
C
R
10
19
Ray-Surface Intersection
Parametric surfaces:Several approaches:
TessellationSubdivisionImplicitizationOther numerical methods (involve solving a system of two or three nonlinear equations)
=
),(),(),(
),(vuzvuyvux
vuS
20
Ray-Plane IntersectionExplicit formulation
Find t, u,v such that:
Linear system 3 equations, 3 unknowns
( , ) ( , ) ( , )( , ) ( , ) ( , )( , ) ( , ) ( , )
x x u v o
y y u v o
z z u v o
O tD x u v x u v x u v xO tD y u v u y u v v y u v yO tD z u v z u v z u v z
+ + = = + + +
11
21
Advantages of Ray Tracing Algorithm
Computes global illuminations effects:ShadowsReflectionsRefractions
Computes visibility and shading at onceConsistent and easy implementationCan be extended easilyCan be parallelized
22
Disadvantages of Ray Tracing
SlowMemory bound – all objects must be kept in memoryDoes not compute all global illuminations effects:
CausticsColor BleedingMore…
12
23
Accelerating Ray Tracing
Four main groups of acceleration techniques:Parallelization, specialized hardwareReducing the total number of rays that are traced⌧Adaptive recursion depth control
Reducing the average cost of intersecting a ray with a scene:⌧Faster intersection calculations⌧Fewer intersection calculations
Using generalized rays⌧beams⌧cones⌧pencils
24
Parallel/Distributed RT
Two main approaches:Each processor is in charge of tracing a subset of the rays. Requires a shared memory architecture, replication of the scene database, or transmission of objects between processors on demand.Each processor is in charge of a subset of the scene (either in terms of space, or in terms of objects). Requires processors to transmit rays among themselves.
13
25
The Ray Tree
26
Accelerating Ray Tracing
Faster intersection calculations:Object-dependent optimizationsBounding volumes
Fewer intersection calculations:Bounding volume hierarchySpatial subdivisions:⌧Uniform grids⌧Octrees⌧BSP-trees⌧Hybrids
Directional techniques⌧The light buffer⌧Ray classification
14
27
Bounding Volumes
Idea: associate with each object a simple bounding volume. If a ray misses the bounding volume, it also misses the object contained therein.Common bounding volumes:
spheresbounding boxesbounding slabs
Effective for additional applications:Clipping accelerationCollision detection
Note: bounding volumes offer no asymptotic improvement!
28
Bounding Boxes
15
29
Bounding Volumes
30
Bounding Volume Hierarchy
Introduced by James Clark (SGI, Netscape) in 1976 for efficient view-frustum culling.
Procedure Procedure IntersectBVH(rayIntersectBVH(ray, node), node)beginbegin
ifif IsLeaf(nodeIsLeaf(node) ) thenthenIntersect(ray, node.object)Intersect(ray, node.object)
else ifelse if IntersectBV(ray,node.boundingVolumeIntersectBV(ray,node.boundingVolume) ) thenthen
foreachforeach child of node dochild of node doIntersectBVH(rayIntersectBVH(ray, child), child)
endforendforendifendif
endend
16
31
Spatial Subdivision
Uniform spatial subdivision:The space containing the scene is subdivided into a uniform grid of cubes “voxels”.Each voxel stores a list of all objects at least partially contained in it.inGiven a ray, voxels are traversed using a 3D variant of the 2D line drawing algorithms.At each voxel the ray is tested for intersection with the primitives stored thereinOnce an intersection has been found, there is no need to continue to other voxels.
32
Uniform Subdivision
17
33
Adaptive Spatial Subdivision
Disadvantages of uniform subdivision:requires a lot of spacetraversal of empty regions of space can be slownot suitable for “teapot in a stadium” scenes
Solution: use a hierarchical adaptive spatial subdivision data structure
octreesBSP-trees
Given a ray, perform a depth-first traversal of the tree Again can stop once
34
Octrees
18
35
Octree traversal
36
Directional Techniques
Light buffer: accelerates shadow rays.Discretize the space of directions around each light source using the direction cubeIn each cell of the cube store a sorted list of objects visible from the light source through that cellGiven a shadow ray locate the appropriate cell of the direction cube and test the ray with the objects on its list
19
37
Directional Techniques
Ray classification (Arvo and Kirk 87):Rays in 3D have 5 degrees of freedom: (x,y,z,θ,φ)Rays coherence: rays belonging to the same small 5D neighborhood are likely to intersect the same set of objects.Partition the 5D space of rays into a collection of 5D hypercubes, each containing a list of objects.Given a ray, find the smallest containing 5D hypercube, and test the ray against the objects on the list.For efficiency, the hypercubes are arranged in a hierarchy: a 5D analog of the 3D octree. This data structure is constructed in a lazy fashion.