Presentation on theme: "GR2 Advanced Computer Graphics AGR"— Presentation transcript:
1 GR2 Advanced Computer Graphics AGR Lecture 14Improving the Efficiency of Ray TracingLight Source Effects
2 Advantages and Disadvantages of Ray Tracing Ray tracing is attractive becauseshadows, reflections, refractions are easily incorporatedRay tracing is expensive becausethe cost of computing ray-object intersections is very highThis part of the lecture looks at efficiency issues in ray tracing
3 Ray Tracing - A Reminder pixel positionson view planecameraThe intensity calculationis now:I = I local + k r * I reflected+ k t * I transmittedI reflected and I transmittedare calculated recursively
4 Adaptive Tree Depth Control Basic algorithm follows rays until they leave the scene (or hit diffuse surface) - in theory the tree depth can then be considerableIn practice, it is not usually necessary to trace rays to any great depthAs tree formed, a running product is kept of transmission and reflection coefficientsthis product attenuates all intensities lower in treeonce product less than threshold, branch is stopped
5 Bounding Volumes Enclose groups of objects in a simple bounding volume sphere or boxTest for intersection against bounding volumeif none, then ray does not intersect objects withinif intersection occurs, test against each object in turnIdea can be extended to hierarchies of bounding volumes (usually boxes)
6 Spatial SubdivisionIdea: divide space into subregions, noting objects in each subregiontermed ‘spatial subdivision’ or ‘spatial coherence’Calculation changes from:for each object or bounding box, find ray intersectiontoas ray proceeds through space, are there any objects in the current subregion?if yes, calculate intersections; if not, move onfind next subregion entered by the ray
7 How do we Subdivide Space One idea is octree partitioningWe illustrate in 2D - known as quadtreeFirst divide space intofour regionsCount number of objectsin each regionIf a region contains an object,subdivide againContinue to a specified levelof subdivision
8 Octree A tree structure emerges, with the nodes at the leaves of the tree containing (hopefully) a small number of objects,or empty.This is quadtree - in 3Dwe subdivide cube into8 each time, getting anoctree
9 Ray Tracing through Octree We trace ray from subregion to subregion, only doingintersection tests for the small number of objects in thesubregion.Find region correspondingto start point. Test ray forintersections with any objects.If none, find next region - bycalculating intersection withregion boundaries. Advancea short way into next region -say to (x,y,z)Find region which includes(x,y,z) and continue.
10 Finding Region Containing (x,y,z) We use octree itself to locate region. Starting at top, asimple test determines in which of eight (4 for quadtree)regions the point (x,y,z) lies. Proceed down tree untilleaf node reached.
11 Binary Space Partitioning An alternative to octrees is just to split into two at each stepseparating plane typically chosen to divide space into regions of equal complexityKnown as Binary Space Partitioning, or BSP, trees
12 Octrees versus BSP trees good for scenes where density of objects varies widelypossible to have small objects in large regionsstepping from region to region slow because trees tend to be unbalancedBSP trees:depth of tree smaller because tree balancedmemory costs lowervoid areas smaller
13 Ray Tracing SoftwarePersistence Of Vision Ray Tracer (POV-RAY) is public domain ray tracing softwareDownload from: