Computer Graphics as Virtual Photography Ray Tracing: Intersection Photography: real scene camera (captures light) photo processing Photographic print processing Computer Graphics: 3D models camera tone model reproduction (focuses simulated lighting) synthetic image Ray Tracing: Intersection We only talked about ray intersection with spheres and planes What about? Boxes Cylinders Cones Triangles Spline surfaces Irregular shapes Ray Tracing - Object - Ray Intersection For each ray, intersection test needs to be made for each object This could costly if you have many objects consider if object has n polygons, n very large! Solutions Adaptive Depth Control Bounding Volume Spatial Subdivision Ray Tracing Adaptive Depth Control Indices of diffuse/reflection/refraction get multiplied together as the ray tracer recurses Depending on material properties, this attenuation can get very small Keep running product and stop when below a threshold Place simple objects (i.e., sphere or box) around complex objects Suitability depends on object being enclosed! Do initial intersection tests on bounding objects. If ray intersects bounding volume, then test complex bounded object Can be nested 1
[Watt/Watt,235] [Watt/Watt,236] Motivation Without spatial subdivision, for each ray, you will need to query all objects/polygons and test for intersection With spatial subdivision, you know which objects are in each volume so you only test objects that are in the volumes where a ray is traveling. Subdivide your scene volume into hierarchical regions Octrees BSP Trees Create a tree structure that indicates for each region: if the region is empty the object present at that particular region Test ray intersection with region volume Ray Tracing - Octrees Ray Tracing - Octrees Recursively subdivide volume into equal regions. If subregion is empty or contains a single object, then stop Otherwise, further subdivide. Continue until each subregion is empty or contains a single object. [Foley/Van Dam] 2
Ray Tracing Oct(quad)trees Subdivisions represented as a tree Ray Tracing - Oct(quad)trees Quadtree applet http://njord.umiacs.umd.edu:1601/users/brabec/qu adtree/points/pointquad.html [Watt/Watt,244] Images from http://www.flipcode.com/tutorials/tut_octrees.shtml Shows viewing frustum and which octants need to be checked. 3
Binary Space Partitioning Trees (BSP Trees) Like Octrees but divides space into a pair of subregions Subregions need not be equally spaced Planes separating regions can be placed at object boundaries. Octrees vs BSP Trees [Watt/Watt,246] BSP Trees Each non-terminal node represents a single partitioning plane that divides space in two BSPTree applet http://symbolcraft.com/graphics/bsp/index.html [Watt/Watt,247] Advantages Efficient means for finding objects within your space Compact representation Disadvantages Preprocessing required If scene changes, must rebuild your tree Not foolproof Potential Problems - can double testing or miss small items [Watt/Watt,247] 4
Octrees vs BSP trees BSP Trees are generally more balanced than Octrees BSP Traversal more efficient BSP Trees have additional storage overhead as must store subdivision planes Summary Intersection Calculations Bounding Volumes Spatial Subdivision Octrees BSPTrees Questions? 5