Upload
cuthbert-douglas
View
221
Download
0
Tags:
Embed Size (px)
Citation preview
David Luebke 04/21/23
CS 551 / 645: Introductory Computer Graphics
David Luebke
http://www.cs.virginia.edu/~cs551
David Luebke 04/21/23
Administrivia
Upcoming graphics events– Graphics lunch: Olsson 236D
Ongoing, informal event; bring your lunch
– “Graphics week”: 2 upcoming colloquia Dec 1: Dan Aliaga (Bell Labs), Image-Based Rendering Dec 6: Ben Watson (U. Alberta), Level of detail control
David Luebke 04/21/23
Recap: Ray Casting
An example:
ScreenEyepoint Scene
David Luebke 04/21/23
Recap: Recursive Ray Tracing
Obvious extension: – Spawn additional rays off reflective surfaces– Spawn transmitted rays through transparent
surfaces
Leads to recursive ray tracing
Primary Ray
Secondary Rays
David Luebke 04/21/23
Recap: Basic Algorithm
Object allObs[];
Color image[];
RayTraceScene()
allObs = initObjects();
for (Y all rows in image)for (X all pixels in row) Ray R = calcPrimaryRay(X,Y);
image[X,Y] = TraceRay(R);display(image);
David Luebke 04/21/23
Recap: Basic Algorithm
Color TraceRay(Ray R)
if rayHitsObjects(R) then
Color localC, reflectC, refractC;
Object O = findNearestObject(R);
localC = shade(O,R);
Ray reflectedRay = calcReflect(O,R)
Ray refractedRay = calcRefract(O,R)
reflectC = TraceRay(reflectedRay);
refractC = TraceRay(refractedRay);
return localC reflectC refractCelse return backgroundColor
David Luebke 04/21/23
Recap: Representing Rays
We represent a ray parametrically: – A starting point O– A direction vector D– A scalar t
O
D
t = 1t < 0
R = O + tDt > 1
David Luebke 04/21/23
Recap: Ray-Polygon Intersection
Find plane equation of polygon:ax + by + cz + d = 0
To find coefficients:N = [a, b, c]
d = N P1
x
yN
P1
P2
d
David Luebke 04/21/23
Recap: Ray-Polygon Intersection
Find intersection of ray and plane:t = -(aOx + bOy + cOz + d) / (aDx + bDy + cDz)
Does polygon contain intersection point Pi ?– One simple algorithm:
Draw line from Pi to each polygon vertex Measure angles between lines (how?) If sum of angles between lines is 360°,
polygon contains Pi
– Slow — better algorithms available
David Luebke 04/21/23
Recap: Shadow Rays
Simple idea: – Where a ray intersects a surface, send a shadow
ray to each light source– If the shadow ray hits any surface before the light
source, ignore light
Note: each ray-surface intersection now spawns n + 2 rays, n = # light sources– Remember: intersections 95% of work
David Luebke 04/21/23
Recap: Shadow Rays
Some problems with using shadow rays as described: – Lots of computation– Infinitely sharp shadows– No semitransparent object shadows
David Luebke 04/21/23
Shadow Ray Problems:Too Much Computation Light buffer (Haines/Greenberg, 86)
– Precompute lists of polygons surrounding light source in all directions
– Sort each list by distance to light source– Now shadow ray need only be intersected with appropriate
list!
Occluding Polys
ShadowRay
Current Intersection Point
Light Buffer
David Luebke 04/21/23
Shadow Rays
Some problems with using shadow rays as described: – Lots of computation– Infinitely sharp shadows– No semitransparent object shadows
David Luebke 04/21/23
Shadow Ray Problems:Sharp Shadows Why are the shadows sharp? A: Infinitely small point light sources What can we do about it? A: Implement area light sources How?
David Luebke 04/21/23
Shadow Ray Problems: Area Light Sources
30% blockage
Could trace a conical beam from point of intersection to light source:
Track portion of beam blocked by occluding polygons:
David Luebke 04/21/23
Shadow Ray Problems:Area Light Sources Too hard! Approximate instead: Sample the light source over its area and
take weighted average:
50% blockage
David Luebke 04/21/23
Shadow Ray Problems:Area Light Sources Disadvantages:
– Less accurate (50% vs. 30% blockage)– Oops! Just quadrupled (at least) number of
shadow rays
Moral of the story: – Soft shadows are very expensive in ray tracing
David Luebke 04/21/23
Shadow Rays
Some problems with using shadow rays as described: – Lots of computation– Infinitely sharp shadows– No semitransparent object shadows
David Luebke 04/21/23
Shadow Ray Problems:Semitransparent Objects In principle:
– Translucent colored objects should cast colored shadows
– Translucent curved objects should create refractive caustics
In practice:– Can fake colored shadows by attenuating color
with distance– Caustics need backward ray tracing
David Luebke 04/21/23
Speedup Techniques
Intersect rays faster Shoot fewer rays Shoot “smarter” rays
David Luebke 04/21/23
Speedup Techniques
Intersect rays faster Shoot fewer rays Shoot “smarter” rays
David Luebke 04/21/23
Intersect Rays Faster
Bounding volumes Spatial partitions Reordering ray intersection tests Optimizing intersection tests
David Luebke 04/21/23
Bounding Volumes
Bounding volumes– Idea: before intersecting a ray with a collection of
objects, test it against one simple object that bounds the collection
0
1
2
3
4
56
78
90
1
2
3
4
56
78
9
David Luebke 04/21/23
Bounding Volumes
Hierarchical bounding volumes– Group nearby volumes hierarchically– Test rays against hierarchy top-down
David Luebke 04/21/23
Bounding Volumes
Different bounding volumes – Spheres
Cheap intersection test Poor fit Tough to calculate optimal clustering
– Axis-aligned bounding boxes (AABBs) Relatively cheap intersection test Usually better fit Trivial to calculate clustering
David Luebke 04/21/23
Bounding Volumes
More bounding volumes– Oriented bounding boxes (OBBs)
Medium-expensive intersection test Very good fit (asymptotically better) Medium-difficult to calculate clustering
– Slabs (parallel planes) Comparatively expensive Very good fit Difficult to calculate good clustering
David Luebke 04/21/23
Spatial Partitioning
Hierarchical bounding volumes surround objects in the scene with (possibly overlapping) volumes
Spatial partitioning techniques classify all space into non-overlapping portions
David Luebke 04/21/23
Spatial Partitioning
Example spatial partitions:– Uniform grid (2-D or 3-D)– Octree– k-D tree– BSP-tree
David Luebke 04/21/23
Uniform Grid
Uniform grid pros:– Very simple and fast to generate– Very simple and fast to trace rays across (How?)
Uniform grid cons:– Not adaptive
Wastes storage on empty space Assumes uniform spread of data
David Luebke 04/21/23
Octree
Octree pros:– Simple to generate– Adaptive
Octree cons:– Nontrivial to trace rays across– Adaptive only in scale
David Luebke 04/21/23
k-D Trees
k-D tree pros:– Moderately simple to generate– More adaptive than octrees
k-D tree cons:– Less efficient to trace rays across– Moderately complex data structure
David Luebke 04/21/23
BSP Trees
BSP tree pros:– Extremely adaptive– Simple & elegant data structure
BSP tree cons:– Very hard to create optimum BSP– Splitting planes can explode storage– Simple but slow to trace rays across
David Luebke 04/21/23
Reordering RayIntersection Tests Caching ray hits (esp. shadow rays) Memory-coherent ray tracing
David Luebke 04/21/23
Optimizing Ray Intersection Tests Fine-tune the math!
– Share subexpressions– Precompute everything possible
Code with care– Even use assembly, if necessary