Speeding Up Ray Tracing

advertisement
Speeding Up Ray Tracing
Images from Virtual Light Field Project
www.cs.ucl.ac.uk/vlf
©Slides Anthony Steed 1999 & Mel Slater 2004
1
Optimisations
Limit the number of rays
 Make the ray test faster

• for shadow rays
– the main drain on resources in there are
several lights
• for primary rays
• for all rays
over 90% of the cost of raytracing is in ray-object
intersection tests
2
Primary Rays
Use a z-buffer!
 Instead of writing colour write and
object identifier

• Easy to support in OpenGL - turn off
lighting, do flat shading and encode object
id within 24bit colour

Difficult technique to use elsewhere
because rays are no longer spatially
coherent and evenly spaced
3
General Rays

Techniques to use
• bounding volumes
• hierarchical bounding volumes
• space subdivision
– regular
– adaptive
• ray coherence
4
Bounding Volume
Find a tight
bounding
volume and use
it for a first
reject test
 If hit volume
then test full
object

Axis aligned
Bounding Box
Bounding Box
Bounding
Sphere
5
Fast BV Tests

Box-Ray test
• a box is three sets of parallel planes, each
set orthogonal to the other two
– Calculate tnear for each of the three plane pairs
– find max of the 3 tnear
– Calculate tfar for each of the three plane pairs
– find min of the 3 tfar
• If max tnear is greater that min tfar, then the
box is not intersected
6
Fast BV Tests (EG)
tnearx
tnearx
tfarx
tfarx
tneary
tfary
7
Choosing a Volume

Choice depends on the cost of the test
and the fit of the shape
• The “void” area can be very large

More efficient fitting shapes are
possible (this is still a research area e.g.
k-dops)
8
Hierarchical Bounding Volumes
r2
r1
root
C
A+B
C
A
A
D
B
D+E
D
F
E
E
B
F
9
Choosing a HBV

Scene graph might not map to a decent
space partitioning
• group BVs based on proximity rather than
scene graph position

You would sort the HBV using a BSP
tree anyway ...
10
Regular Spatial Subdivision

Regular 3D grid of “voxels”
A
B
C
11
Details on the RSS

Testing
• Each voxel keeps a list of
objects that intersect this
voxel
• Need for a ‘mailbox’
system where voxel also
keeps track of what has
already intersected it to
avoid duplications.

Size of voxels
• Obvious trade off on
granularity of voxels
12
Adaptive Spatial Subdivision

The octree idea (illustrated with a
quadtree!)
13
Building the Octree

Recursively split the cells into eight,
until each cell meets some criteria
• e.g. previous diagram was “only one object
intersects each cell”

Advantage is clear - cells are not
wasted on void areas
14
Tracing an Octree
Find octree cell containing start point
 If no intersection, find intersection (I) of
ray with cube that surround the octree
 Find (I) in the octree

• it is moved a little along the ray

Repeat
15
kD-tree / BSP Tree

Similar to octree, but orthogonal
splitting planes are chosen to provide a
good search tree
Split based on
balancing object
numbers and
minimising volume
disparity
16
Ray Coherence Methods
Light Buffer
 Ray Classification Scheme

17
Light Buffer
Haines and Greenberg, 1986
 Problem with shadow rays is that for
every intersection we trace and
additional n rays for each light

l1
r
l0
18
Light Buffer
Enclose light in a box.
 Cells of box faces store objects

19
Construction - 2D Analogue
B
C1
C
C2
C3
A
C4
C1 - <NULL>
C2 - A, B, C
C3 - A
C4 - <NULL>
20
Ray Classification
Arvo and Kirk, 1987
 Group together similar rays (rather than
similar objects)
 Similar rays should intersect the same
groups of objects
 Very elegant method

21
Ray Classification - Rays are Points

Every ray is represented as a point in
5D space (R5) (x,y,z,u,v) where (u,v) is
the directional component, and (x,y,z) is
the origin
There are 6 planes
-X,+X,-Y,+Y,-Z,+Z
-Y
(x,y,z)
(u,v)
This ray is
(x,y,z) inside box
in direction (u,v)
on +X plane
+X
22
Ray Classification – 5 Tasks


E is the subset of R5 containing every possible ray in
the scene
E1, E2, …, En is a partition of E
• formed as a 32-tree
– The 5D hypercube can be split along each of its axis to form 32
children, and so on…




For each Ei there will be a Ci - a set of objects
intersected by at least one of the ray s in Ei
For any ray find the Ei to which it belongs
Then intersect it with the objects in Ci
(see details in the book – the important aspect to
undrestand is the idea of ray classification – similar
rays will intersect similar groups of objects!).
23
Virtual Light Field Approach





Very recent development
For a fixed ‘uniformly distributed’ set of rays,
find for each ray all of its intersections with
objects in the environment
Each ray maintains a list of objects it
intersects (and where along the ray)
Given any arbitrary ray that emerges in ray
tracing, find the closest ray in the ray set, and
use the rays that this intersects as a
candidate set of objects.
Several complications – but the idea is clear.
24
Summary


Ray intersection is computationally expensive
and we need to reduce it
Methods used fall into 3 classes
• Bound the objects
• Partition the object space
• Partition the ray space

Ray tracing can be tremendously speeded up
by appropriate use of modern hardware (see
papers of Ward et al, and also UCL’s Virtual
Light Field project www.cs.ucl.ac.uk/vlf ).
25
Download