Effects needed for realism Global Rendering Computer Graphics 1, Fall 2005 Lecture 7 4th ed.: Ch 6.10, 12.1-12.5 Shadows Reflections (Mirrors) Transparency Interreflections Detail (Textures etc.) Complex Illumination Realistic Materials and many more The Rendering Equation The infinite scattering and absorption of light can be described by the rendering equation Cannot be solved in general A ray tracer is best suited for perfectly reflecting surfaces A radiosity renderer is best suited for perfectly diffuse surfaces Global effects of the rendering equation shadow multiple reflection translucent surface Local vs global rendering Correct shading requires a global calculation involving all objects and all light sources Incompatible with the pipeline model which shades each polygon independently (local rendering) However, in computer graphics, especially real-time graphics, we are happy if things look right There exist many techniques for approximating global effects Light-material interaction Light that strikes an object is partially absorbed and partially scattered (reflected) The amount reflected determines the color and brightness of the object The reflected light is scattered in a manner that depends on the smoothness and orientation of the surface Ingela Nyström 1
Ambient light only Diffuse light Diffuse shading is based on the principal that more light hits the surface of an object where the angle between the surface normal and the vector from the intersection to the light is least Source:www.2tothex.com/rayt Camera light source: no shadows Shadows Shadows are simple to compute in a ray tracer. A point is in shadow if a ray from that point to the light source intersects an object Source: www.2tothex.com/raytracing/ The point of intersection of a ray and the object has already been calculated in order to apply diffuse shading Distant light source: parallel rays Point light source: see shadows Ingela Nyström 2
Spotlight: cone angle 30, high contrast Spotlight - soft shadows Effect of distance - no attenuation Effect of distance - attenuation 1/distance Effect of distance more attenuation Global illumination Ray tracing Radiosity Image sources and ray tracer: http://www.povray.org http://www.irtc.org 1/(distance) 2 Ingela Nyström 3
Ray tracing Recursive ray tracing function I reflected and I transmitted are calculated recursively color c = trace(point p, vector d, int step) { color local, refl, trans; point q; normal n; camera pixel positions on view plane See pseudo-code on page 630, Angel 4th ed. if (step > MAX) return bgr; q = intersect(p, d, status); if (status == light_source) return light; if (status == no_intersect) return bgr; n = normal(q); r = reflect(q, n); t = transmit(q, n); Intensity calculation: I = I local + k r * I reflected + k t * I transmitted local = phong(q, n, r); refl = trace(q, r, step+1); trans = trace(q, t, step+1); } return(local+refl+trans); Recursive ray tracing The recursion will stop if the maximum no of steps is reached returns background colour if the ray does not intersect any object returns background colour Advantages and disadvantages Ray tracing is attractive because shadows and reflections are easily incorporated Ray tracing is expensive because the cost of computing ray-object intersections is very high if the ray intersects the light source returns light source colour Reflections Ray tracing paths form a ray tree Reflections are generated using ray tracing. In real life, the interaction of light with a reflective object occurs as follows: 1. A light source emits photons 2. Photons collide with and bounce off objects (some energy is absorbed and we see colour) 3. Photons travel into the eye Ra Tc C Rc Ra A PRP D Rb Ta B A Ra C Rc Tc D Rd Ta B Rb Perspective Reference Point Ingela Nyström 4
Calculating intersections The bottle-neck lies in the computation of intersections between ray and object Limit the objects to which we find ray intersections easily sphere plane inside/outside polygon Bounding volumes Enclose groups of objects in a simple bounding volume (sphere or box) Test for intersection against bounding volume if no intersection, then ray does not intersect objects within the bounding volume if intersection occurs, then test against each object in turn How do we subdivide space? One idea is octree partitioning We illustrate in 2D - known as quadtree Octree A tree structure emerges, with the nodes at the leaves of the tree containing (hopefully) a small number of objects, or empty 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 This is a quadtree in 3D, we subdivide the cube into 8 each time, getting an octree Ray tracing through octree We trace the ray from subregion to subregion, only performing intersection tests for the small number of objects in the subregion Find the region corresponding to the start point. Test ray for intersections with any objects. Finding region containing (x,y,z) We use the octree to locate the region containing (x,y,z). Starting at the top, a simple test determines which of the 8 (4 for quadtree) regions that contains the point. Proceed down the tree until leaf node reached. If none, find the next region by calculating intersection with the region boundaries. Advance a short way into next region - say to (x,y,z) Find the region that includes (x,y,z) and continue. Ingela Nyström 5
Binary space partitioning An alternative to octrees is to split the space into two at each step a separating plane is typically chosen to divide the space into regions of equal complexity Known as Binary Space Partitioning (BSP) trees Octrees vs BSP trees Octrees: 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 small because tree balanced memory costs lower void areas smaller The room model Local models do not consider indirect illumination Direct Direct P b B P a A Global models consider indirect illumination P b Indirect B Indirect P a A Global models ray tracing, radiosity Ingela Nyström 6
Radiosity The opposite of ray-tracing The light-transfer calculations are based solely on the geometry of the environment There is no view position or viewer Radiosity Radiosity considers only the interaction of light with surfaces in the environment The benefit of this algorithm is that visual brightness for each object need only be calculated once Ingela Nyström 7
Which one looks real? 3D Photorealistic Rendering 1. Wire-frame Less Realism 2. Hidden-surface removal 3. Local illumination 4. Global illumination More Realism Ingela Nyström 8
The POVRAY Teapot Ingela Nyström 9