anti-aliased and accelerated ray tracing
TRANSCRIPT
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell
Anti-aliased and acceleratedray tracing
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 2
ReadingRequired:
Watt, sections 12.5.3 – 12.5.4, 14.7Further reading:
A. Glassner. An Introduction to Ray Tracing. AcademicPress, 1989. [In the lab.]
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 3
Aliasing in renderingOne of the most common rendering artifacts is the“jaggies”. Consider rendering a white polygonagainst a black background:
We would instead like to get a smoother transition:
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 4
Anti-aliasingQ: How do we avoid aliasing artifacts?
1. Sampling:2. Pre-filtering:3. Combination:
Example - polygon:
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 5
Polygon anti-aliasing
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 6
Antialiasing in a ray tracerWe would like to compute the average intensity in the neighborhood ofeach pixel.
When casting one ray per pixel, we are likely to have aliasing artifacts.To improve matters, we can cast more than one ray per pixel andaverage the result.A.k.a., super-sampling and averaging down.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 7
Speeding it upVanilla ray tracing is really slow!Consider: m x m pixels, k x k supersampling, and nprimitives, average ray path length of d, with 2 rays castrecursively per intersection.Complexity =For m=1,000,000, k = 5, n = 100,000, d=8…veryexpensive!!In practice, some acceleration technique is almost alwaysused.We’ve already looked at reducing d with adaptive raytermination.Now we look at reducing the effect of the k and n terms.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 8
Antialiasing by adaptive samplingCasting many rays per pixel can be unnecessarily costly.For example, if there are no rapid changes in intensity atthe pixel, maybe only a few samples are needed.Solution: adaptive sampling.
Q: When do we decide to cast more rays in a particulararea?
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 9
Let’s say you were intersecting a ray with a polyhedron:
Straightforward methodintersect the ray with each trianglereturn the intersection with the smallest t-value.
Q: How might you speed this up?
Faster ray-polyhedron intersection
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 10
Ray Tracing Acceleration Techniques
1N
Faster Intersection
Fewer Rays
Generalized Rays
Approaches
Tighter boundsFaster intersector
Uniform gridsSpatial hierarchies k-d, oct-tree, bsp hierarchical gridsHierarchical bounding volumes (HBV)
Early ray terminationAdaptive sampling
Beam tracingCone tracingPencil tracing
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 11
Uniform spatial subdivisionAnother approach is uniform spatial subdivision.
Idea:Partition space into cells (voxels)Associate each primitive with the cells it overlapsTrace ray through voxel array using fast incremental arithmetic tostep from cell to cell
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 12
Uniform Grids
Preprocess sceneFind bounding box
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 13
Uniform Grids
Preprocess sceneFind bounding box
Determine resolutionv x y z on n n n n= !
3max( , , )x y z on n n d n=
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 14
Uniform Grids
Preprocess sceneFind bounding boxDetermine resolution
Place object in cell, ifobject overlaps cell
3max( , , )x y z on n n d n=
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 15
Uniform Grids
Preprocess sceneFind bounding boxDetermine resolution
Place object in cell, ifobject overlaps cellCheck that objectintersects cell
3max( , , )x y z on n n d n=
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 16
Uniform Grids
Preprocess sceneTraverse grid3D line – 3D-DDA6-connected line
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 17
Caveat: Overlap
Optimize for objects that overlap multiple cells
Traverse until tmin(cell) > tmax(ray)Problem: Redundant intersection tests:Solution: Mailboxes
Assign each ray an increasing numberPrimitive intersection cache (mailbox)
Store last ray number tested in mailboxOnly intersect if ray number is greater
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 18
Non-uniform spatial subdivisionStill another approach is non-uniform spatial subdivision.
Other variants include k-d trees and BSP trees.
Various combinations of these ray intersections techniques are alsopossible. See Glassner and pointers at bottom of project web page formore.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 19
Non-uniform spatial subdivisionBest approach - k-d trees or perhaps BSP trees
More adaptive to actual scene structureBSP vs. k-d tradeoff between speed from simplicity and better adaptability
0
1
2
4
7 8
5 6
3
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 20
Spatial Hierarchies
A
A
Letters correspond to planes (A)Point Location by recursive search
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 21
Spatial Hierarchies
B
A
B
A
Letters correspond to planes (A, B)Point Location by recursive search
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 22
Spatial Hierarchies
CB
D
C
D
A
B
A
Letters correspond to planes (A, B, C, D)Point Location by recursive search
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 23
Variations
oct-treekd-tree bsp-tree
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 24
Ray Traversal Algorithms
Recursive inorder traversal[Kaplan, Arvo, Jansen]
mint
maxt *t
max*t t<
*t
min max*t t t< <
*t
min*t t<
Intersect(L,tmin,tmax) Intersect(R,tmin,tmax)Intersect(L,tmin,t*)Intersect(R,t*,tmax)
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 25
Build Hierarchy Top-Down
Choose splitting plane• Midpoint• Median cut• Surface area heuristic
?
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 26
Surface Area and RaysNumber of rays in a given direction that hit anobject is proportional to its projected area
The total number of rays hitting an object isCrofton’s Theorem:
For a convex body
For example: sphere 4
SA =
4 A!
24S r!=
A
2A A r!= =
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 27
Surface Area and Rays
The probability of a ray hitting a convex shapethat is completely inside a convex cell equals
Pr[ ] o
o c
c
Sr S r S
S! ! =
oSc
S
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 28
Surface Area Heuristic
t a a i b b iC t p N t p N t= + +
80i tt t=a b
it
tt
Intersection time
Traversal time
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 29
Surface Area Heuristic
aa
Sp
S= b
b
Sp
S=
2n splits
a b
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 30
Hierarchical bounding volumesWe can generalize the idea of bounding volume acceleration withhierarchical bounding volumes.
Key: build balanced trees with tight bounding volumes.
Many different kinds of bounding volumes.Note that bounding volumes can overlap.