Presentation on theme: "GR2 Advanced Computer Graphics AGR"— Presentation transcript:

Lecture 14 Improving the Efficiency of Ray Tracing Light Source Effects

Ray tracing is attractive because shadows, reflections, refractions are easily incorporated Ray tracing is expensive because the cost of computing ray-object intersections is very high This part of the lecture looks at efficiency issues in ray tracing

Ray Tracing - A Reminder
pixel positions on view plane camera The intensity calculation is now: I = I local + k r * I reflected + k t * I transmitted I reflected and I transmitted are calculated recursively

Basic algorithm follows rays until they leave the scene (or hit diffuse surface) - in theory the tree depth can then be considerable In practice, it is not usually necessary to trace rays to any great depth As tree formed, a running product is kept of transmission and reflection coefficients this product attenuates all intensities lower in tree once product less than threshold, branch is stopped

Bounding Volumes Enclose groups of objects in a simple bounding volume
sphere or box Test for intersection against bounding volume if none, then ray does not intersect objects within if intersection occurs, test against each object in turn Idea can be extended to hierarchies of bounding volumes (usually boxes)

Spatial Subdivision Idea: divide space into subregions, noting objects in each subregion termed ‘spatial subdivision’ or ‘spatial coherence’ Calculation changes from: for each object or bounding box, find ray intersection to as ray proceeds through space, are there any objects in the current subregion? if yes, calculate intersections; if not, move on find next subregion entered by the ray

How do we Subdivide Space
One idea is octree partitioning We illustrate in 2D - known as quadtree First divide space into four regions Count number of objects in each region If a region contains an object, subdivide again Continue to a specified level of subdivision

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 3D we subdivide cube into 8 each time, getting an octree

Ray Tracing through Octree
We trace ray from subregion to subregion, only doing intersection tests for the small number of objects in the subregion. Find region corresponding to start point. Test ray for intersections with any objects. If none, find next region - by calculating intersection with region boundaries. Advance a short way into next region - say to (x,y,z) Find region which includes (x,y,z) and continue.

Finding Region Containing (x,y,z)
We use octree itself to locate region. Starting at top, a simple test determines in which of eight (4 for quadtree) regions the point (x,y,z) lies. Proceed down tree until leaf node reached.

Binary Space Partitioning
An alternative to octrees is just to split into two at each step separating plane typically chosen to divide space into regions of equal complexity Known as Binary Space Partitioning, or BSP, trees

Octrees versus BSP trees
good for scenes where density of objects varies widely possible to have small objects in large regions stepping from region to region slow because trees tend to be unbalanced BSP trees: depth of tree smaller because tree balanced memory costs lower void areas smaller

Ray Tracing Software Persistence Of Vision Ray Tracer (POV-RAY) is public domain ray tracing software Download from:

More Teapots! The POVRAY version

POVLAB modeller

Lecture 14 Part 2 Light Source Effects

Light Source Sequence of Images
The following sequence of images were created by Alan Watt of University of Sheffield They illustrate effects of different light sources in a scene

Ambient Light Only

Camera Light Source Light source at camera only. Note no shadows.

Distant Light Source Light rays parallel to each other Note shadows

Point Light Source Point light source close to object,
in same direction as distant source in previous picture. Note shadows are different.

Spotlight Spotlight in same position as previous point light.
Cone angle is 30 deg. Note cone of influence of the light, and the hard shadow.

Softer shadow obtained by having a gradual drop-off of intensity at edge of cone (here over last 5 deg)

Effect of Distance - No Attenuation
Here there is no attenuation of light over distance

Effect of Distance - Attenuation
Intensity is attenuated by 1/distance

Effect of Distance - Attenuation
Here the attenuation factor is 1/(distance)2

Fog Intensity of fog increases linearly with depth. How is this
achieved?

Similar presentations