Slide 1OverviewLast lectureAcceleration structuresAcceleration structuresSpatial hierarchies: gridsSpatial hierarchies: kd-treesSpatial hierarchies: kd-treesRT with the kd-tree (2)RT with the kd-tree (3)RT with the kd-tree (4)Kd-tree traversalObject hierarchies: BVHsBounding volumesBVH traversalChoosing a structureChoosing a structureChoosing a structureOverviewRay PacketsRay coherenceBVH traversalBVH packet traversalRay packet advantagesData parallelismData parallelismSIMD ray processingOptimized hierarchy constructionRay Tracing, Part 2Christian LauterbachCOMP 770, 2/16/2009OverviewAcceleration structuresSpatial hierarchiesObject hierarchiesInteractive Ray Tracing techniquesRay packetsOptimized hierarchy constructionLast lectureRay TracingFor each pixel: generate rayFor each primitive:Does ray hit primitive?Yes: Test depth / write colorThat means linear time complexity in number of primitives!Acceleration structuresGoal: fast search operation for ray that returns all intersecting primitives Then test only against thoseOperation should take sub-linear timeIn practice: conservative supersetAcceleration structuresBroad classification:Spatial hierarchiesGridsOctreesKd-trees, BSP treesObject hierarchiesBounding volume hierarchiesSpatial kd-treesSpatial hierarchies: gridsRegular subdivision of space into cellsCells almost always cubesEach object is referenced in each cell it overlapsNested grids also possibleRay tracing with the grid:Find entry cell of rayFor each cell:Intersect with all objects in cell. If hit, terminate.Otherwise, walk to next cell ray can hitSpatial hierarchies: kd-treesBinary tree of space subdivisionsEach is axis-aligned plane xy ySpatial hierarchies: kd-treesTraversing a kd-tree: recursiveStart at root nodeFor current node:If inner node:Find intersection of ray with planeIf ray intersects both children, recurse onnear side, then far sideOtherwise, recurse on side it intersectsIf leaf node:Intersect with all object. If hit, terminate.RT with the kd-tree (2)ray 1ray 2ray 3split plane'near' node 'far' nodewhat can the ray possibly hit?RT with the kd-tree (3)three cases:hitpoint above split: far node onlyhitpoint below split: near node onlyotherwise: near, then far'above' and 'below' rather vagueuse distance t along ray ray = origin + t *directionRT with the kd-tree (4)when does the ray intersect?split planesplit plane'near' node 'far' node'near' node 'far' nodet_mint_mint_maxt_maxt_splitt_splitKd-tree traversalSimple and fast implementationIn practice: using stack, not recursionVery quick intersection test (couple FLOPS + tests)Overall: logarithmic complexity for each rayObject hierarchies: BVHsDifferent approach: subdivide objects, not spaceHierarchical clustering of objectsEach cluster represented by bounding volumeBinary treeEach parent node fully contains childrenBounding volumesPractically anything can be bounding volumeJust need ray intersection methodTypical choices:SpheresAxis-aligned bounding boxes (AABBs)Oriented bounding boxes (OBBs)k-DOPsTrade-off between intersection speed and how closely the BV encloses the geometryBVH traversalRecursive algorithm:Start with root nodeFor current node:Does ray intersect node’s BV? If no, returnIs inner node?Yes, recurse on childrenIs leaf node?Intersect with object(s) in node, store intersection resultsNote: can’t return after first intersection!Choosing a structureThere is no ‘best’ acceleration structureAll have pros and consGrid:+ fast construction- bad for high local detail (teapot/stadium)Choosing a structureThere is no ‘best’ acceleration structureAll have pros and conskd-tree:+ fast traversal- expensive build, only static scenesChoosing a structureThere is no ‘best’ acceleration structureAll have pros and consBVH:+ can be updated for dynamic scenes- traversal more expensive than kd-treeOverviewAcceleration structuresSpatial hierarchiesObject hierarchiesInteractive Ray Tracing techniquesRay packetsOptimized hierarchy constructionRay PacketsOften have large set of rays close togetherIdea:trace rays in coherent groups (ray packets)ViewerScreenRay coherenceHow does this change tracing?Traversal and object intersectionwork on group of rays at a timeAlso generate secondary (shadow, …) rays in packetsGeneral idea:If one ray intersects, all are intersectedBVH traversalRecursive algorithm:Start with root nodeFor current node:Does ray intersect node’s BV? If no, returnIs inner node?Yes, recurse on childrenIs leaf node?Intersect ray with all object(s) in node, store intersection resultsBVH packet traversalRecursive algorithm:Start with root nodeFor current node:Does any ray intersect node’s BV? If no, returnIs inner node?Yes, recurse on childrenIs leaf node?Intersect all rays with all object(s) in node, store intersection resultsRay packet advantagesWhy does this make things faster?Less memory bandwidth: nodes/objects only loaded once for rays in packetAllows data parallel processing!Current CPUs: e.g. Intel SSEAll GPUsDisadvantage:Rays can be intersected with objects/nodes they would never hit!Data parallelismEssentially vector operations (SIMD)Operations work on all elements in parallelv1 v2 v3 v4 v5 v6 v7 v8v1 v2 v3 v4 v5 v6 v7 v8w1 w2 w3 w4 w5 w6 w7 w8+=v1+w1 v2+w2 v3+w3 v4+w4 v5+w5 v6+w6 v7+w7 v8+w8Data parallelismVector operations usually as fast as a single scalar operationIntel SSE: 4-wide vectorsGPUs: 8-32 wide Cell: 4-wideVector processors: up to 64,000!SIMD ray processingCan use SIMD units to parallelize for raysEach vector has one component from one rayThus, can process small group at same speed as one ray!ray1ray2ray3ray4ray5ray6ray7ray8triitriitriitriitriitriitriitriitriiOptimized hierarchy constructionThe way the hierarchy is constructed has high impact on traversal
View Full Document