CS 376 Introduction to Computer Graphics 04 / 16 / 2007 Instructor: Michael Eckmann
Michael Eckmann - Skidmore College - CS Spring 2007 Today’s Topics Questions? bump mapping radiosity reducing ray-object intersection calculations
Limitation of texture and environment mapping One could create a texture map/environment map of the look of a bumpy surface and then use that to color an object. But what's a limitation of these methods –what if lighting in the scene changes? –what if the viewpoint changes?
Bump mapping Texture mapping and environment mapping cannot handle the view dependent & lighting dependent nature of shadows and other effects that are seen on surfaces that are bumpy like raisins, oranges, etc. To achieve details based on lighting calculations, bump mapping can be used. Bump mapping takes a simple smooth mathematical surface like a sphere or other curved surface as its model, but renders it so that it does not appear smooth --- before the lighting calculations are done, the surface normals are perturbed across the surface. The normal at a particular surface point is the key to lighting that point of the surface. Therefore, changing the surface normals causes the surface to be rendered as not smooth.
Bump mapping The sphere or other mathematically described parametric surface that we are rendering will be defined as a function P(u,v), where u and v are the parameters and P(u,v) the positions on the surface. The actual normal (before bump mapping) of a point on the surface at P(u,v) can be calculated as the cross product of the vectors representing the slopes in the u and v directions. The slopes are the partial derivatives of P with respect to u and v (the parameters.) I'll draw a picture on the board for this (unfortunately there is no diagram in the book to describe this). Notation: P u is the partial derivative of P with respect to u P v is the partial derivative of P with respect to v the normal N is: N = P u x P v
Bump mapping N = P u x P v n = N / |N| make n a unit vector We use a bump function B(u,v) that generates relatively small values that will be added to our points from P(u,v). We compute a perturbed normal for the point by first –adding B(u,v) to P in the direction of n to get P' P'(u,v) = P(u,v) + B(u,v) n –then compute N' (which is the normal at P') to be N' = P' u x P' v –now we have to figure out what P' u and P' v are Note: the use here of the ' is NOT notation for derivative.
Bump mapping We know that P'(u,v) = P(u,v) + B(u,v) n so, P' u = partial derivative with respect to u of (P + B n) which is P u + B u n + Bn u and, P' v = partial derivative with respect to v of (P + B n) which is P v + B v n + Bn v we assume that the magnitude of B is small so we can ignore the last term in both equations to get approximations like: P' u = P u + B u n and P' v = P v + B v n
Bump mapping We need to calculate N' = P' u x P' v so, N' = ( P u + B u n ) x ( P v + B v n ) which after we do the math is (P u x P v ) + B v (P u x n) + B u (n x P v ) + B u B v (n x n) n x n = 0, so we get a good approximation for N' to be (P u x P v ) + B v (P u x n) + B u (n x P v ) then we should normalize (make unit magnitude) the N'
Bump mapping Now that we have the N' (the perturbed normal) at the point, what do we do?
RayTracing / Radiosity Ray Tracing is a type of direct llumination method in image space. Direct illumination in image space because the scene that we're rendering is made up of surfaces and lights and we compute the colors of the pixels one at a time. –If the view moves --- have to ray trace again –If the world moves --- have to ray trace again Ray tracing results in some realism but with a few drawbacks + Handles both diffuse and specular reflections as well as refractions –Compute intensive –Shadows are too crisp Radiosity is a type of global illumination method that works in object space. + If the view moves, we DO NOT have to rerun the radiosity algorithm = view independent –Only diffuse, no specular reflection (therefore no mirrorlike surfaces) + Shadows are softer, more realistic +/- Color bleeds from surfaces to nearby surfaces Radiosity and Ray tracing can be combined to produce a more realistic image than either one separately.
Radiosity What follows is an overview of radiosity We won't go into as much detail as ray tracing I can point you to some sources if you wish to learn more about radiosity
Radiosity Light reflects off of surfaces and onto other surfaces. The amount of reflected light that hits a surface is determined by –how much it is attenuated and –how much is absorbed before reflection. When some light is reflected off of surface S the color of the surface S colors that reflected light to some extent. This reflected light then hits other surface(s). This effect causes color bleeding from one surface to another. Example image of radiosity “color bleeding”. Radiosity is a method of rendering a scene by considering the global illumination of the scene (as opposed to the way ray tracing does it) –scene is divided into patches (generally the smaller the better) –a patch will emit (if it's a light source) and reflect light uniformly over its surface
Radiosity Radiosity assumes –surfaces are diffuse emitters and diffuse reflectors –the emitting and reflecting is done uniformly over a “patch” –all light energy in the scene will be conserved --- either absorbed or reflected The radiosity of a surface is computed to be the sum of the light energy emitted (if a light source) and the (incident) light energy hitting the surface (coming from elsewhere). Attenuation is taken care of by –Form Factors (which represents the fraction of the light that is transferred from one surface to another) and –Reflectivity values (which represents the fraction of the light that is reflected from a surface)
Radiosity The Form Factor (the fraction of light that arrives at one surface from another) is computed based on –areas of the 2 surfaces involved –angles between the light travelling from one surface to the other and the surface normals –see text if you would like details A form factor is defined between all directed pairs of patches. F jk is the form factor from patch j to k it is the light energy incident on patch k divided by the total light energy leaving patch j
Radiosity The radiosity equation for a patch k, in a scene with n patches is: B k = E k + p k * Sum n j=1 [ B j F jk ] B k is the radiosity of patch k E k is the light emitted from patch k p k is the reflectivity fraction for patch k (the fraction of incident light that is reflected in all directions) F jk is the form factor from patch j to k
Radiosity For all n patches in the scene you have a radiosity equation that is based on the radiosity of all the n patches. To compute the radiosities you have to solve the n simultaneous equations. –Techniques exist to solve a system of simultaneous equations so not to worry, but it could be expensive The more patches we have the longer the radiosity calculations take, but the prettier our pictures will look (up to some point where reducing the size of our patches will not have any noticeable effect on the picture). Radiosity is compute intensive but the surfaces can have their radiosities precomputed if the world does not change. The radiosities are view independent. Therefore the radiosity of each patch can be precomputed and stored with the patch.
RayTracing / Radiosity Revisit the comparison Ray tracing results in some realism but with a few drawbacks + Handles both diffuse and specular reflections as well as refractions –Compute intensive –Shadows are too crisp –If the viewer moves --- have to ray trace again –If the world moves --- have to ray trace again Radiosity is a type of global illumination method that works in object space. + If the view moves, we DO NOT have to rerun the radiosity algorithm = view independent –Only diffuse, no specular reflection (therefore no mirrorlike surfaces) + Shadows are softer, more realistic + Color bleeds from surfaces to nearby surfaces (diffuse-diffuse reflections)
RayTracing / Radiosity Radiosity and Ray tracing can be combined to produce a more realistic image than either one separately. Radiosity algorithm would execute on the first pass and store the output with the surfaces. Then do Ray Tracing next based on viewer position. If the viewer position changes, but the world stays constant, radiosity does NOT need to be rerun (therefore we can precompute the radiosity of a scene.) However, radiosity would need to be rerun if the world changes in any way (e.g. lights move, objects move, etc.)
Reducing Intersection calcs Let's return to ray tracing for a minute Our text says that ray-object intersection calculations can make up up-to 95% of the processing time of the ray tracer. Reducing this would obviously be worth the effort.
Reducing Intersection calcs enclose objects that are near each other within a bounding volume (e.g. a sphere, a cube, etc.) do this for all the clusters of objects that are in your world then when testing for ray object intersections, first determine which bounding volumes the ray intersects with then only among the objects in those bounding volumes that the ray intersects with do we try to compute the ray- object intersection –all the objects in all the bounding volumes that do not intersect the ray can be ignored picture on the board
Reducing Intersection calcs Space subdivision methods –picture the world in a large cube which is subdivided into smaller cubes cubes that contain surfaces can be subdivided into 8 smaller cubes can do this until you get some programmer-defined maximum numbers of allowable surfaces inside a cube –can store these cubes in a binary partition tree –shoot a ray and find out which small cube it first intersects with if the cube doesn't contain any surfaces continue down the ray to find the next cube it hits and so on if there are surface(s) inside the cube determine if there's an intersection if so, that's the one we use; if not, continue with next cube... picture on the board
Reducing Intersection calcs smaller maximum number of surfaces per cube implies less ray-object intersection calculations however, this leads to an increase in the number of cubes which increases the calculation to determine the ray path through the cubes