410 likes | 1.09k Views
Illumination, Lighting and Shading Model Pradondet Nilagupta Dept. of Computer Engineering Kasetsart University Definitions (1/2) Illumination : the transport of energy (in particular, the luminous flux of visible light) from light sources to surfaces & points
E N D
Illumination, Lighting and Shading Model Pradondet Nilagupta Dept. of Computer Engineering Kasetsart University 204481 Foundation of Computer Graphics
Definitions (1/2) • Illumination: the transport of energy (in particular, the luminous flux of visible light) from light sources to surfaces & points • Note: includes directand indirect illumination • Lighting: the process of computing the luminous intensity (i.e., outgoing light) at a particular 3-D point, usually on a surface • Shading: the process of assigning colors to pixels 204481 Foundation of Computer Graphics
Definitions (2/2) • Illumination models fall into two categories: • Empirical: simple formulations that approximate observed phenomenon • Physically-based: models based on the actual physics of light interacting with matter • We mostly use empirical models in interactive graphics for simplicity • Increasingly, realistic graphics are using physically-based models 204481 Foundation of Computer Graphics
Lighting Model • Many different models exist for simulating lighting reflections • Most models break lighting into constituent parts • ambient reflections • diffuse reflections • specular highlights 204481 Foundation of Computer Graphics
Lighting Model Component • Material Properties • used to describe an objects reflected colors • Surface Normals • Light Properties • used to describe a lights color emissions • Light Model Properties • “global” lighting parameters 204481 Foundation of Computer Graphics
Components of Illumination • Surface properties • Reflectance spectrum (i.e., color of the surface) • Geometric attributes • Position • Orientation • Micro-structure • Light sources (or emitters) • Spectrum of emittance (i.e, color of the light) • Geometric attributes • Position • Direction • Shape • Directional attenuation 204481 Foundation of Computer Graphics
Ambient Light Sources • Objects not directly lit are typically still visible • E.g., the ceiling in this room, undersides of desks • This is the result of indirect illumination from emitters, bouncing off intermediate surfaces • Too expensive to calculate (in real time) Ireflected = kambient Iambient 204481 Foundation of Computer Graphics
Directional Light Sources • all rays of light from the source are parallel • As if the source is infinitely far away from the surfaces in the scene • A good approximation to sunlight • direction is constant for all surfaces in the scene 204481 Foundation of Computer Graphics
Point Light Sources • A point light source emits light equally in all directions from a single point • The direction to the light from a point on a surface thus differs for different points: 204481 Foundation of Computer Graphics
Other Light Sources • Spotlights are point sources whose intensity falls off directionally. • Supported by OpenGL • Area light sources define a 2-D emissive surface (usually a disc or polygon) • Good example: fluorescent light panels 204481 Foundation of Computer Graphics
Reflection • Ambient Reflections • Diffuse Reflection • Specular Reflections 204481 Foundation of Computer Graphics
Ambient Reflections • Color of an object when not directly illuminated • Think about walking into a room with the curtains closed and lights off 204481 Foundation of Computer Graphics
l n Diffuse Reflections • Color of an object when directly illuminated • often referred to as base color • The angle between the surface normal and the incoming light is the angle of incidence: Idiffuse = kd Ilightcos • In practice we use vector arithmetic: Idiffuse = kd Ilight(n • l) 204481 Foundation of Computer Graphics
Specular Reflections • Shiny surfaces exhibit specular reflection • Polished metal • Glossy car finish • A light shining on a specular surface causes a bright spot known as a specular highlight 204481 Foundation of Computer Graphics
Phong Lighting Model • Using surface normal • OpenGL’s lighting model based on Phong’s 204481 Foundation of Computer Graphics
OpenGL Material Properties • GL_AMBIENT • GL_DIFFUSE • GL_SPECULAR • GL_SHININESS • GL_EMISSION 204481 Foundation of Computer Graphics
Computing Surface Normals • Lighting needs to know how to reflect light off the surface • Provide normals per • face - flat shading • vertex - Gouraud shading • pixel - Phong shading • OpenGL does not support Phong natively 204481 Foundation of Computer Graphics
Face Normals • Same normal for all vertices in a primitive • results in flat shading for primitive glNormal3f( nx, ny, nz ); glBegin( GL_TRIANGLES ); glVertex3fv( v1 ); glVetrex3fv( v2 ); glVertex3fv( v3 ); glEnd(); 204481 Foundation of Computer Graphics
Computing Face Normals ( Polygons ) • We’re using only planar polygons • Can easily compute the normal to a plane • use a cross product 204481 Foundation of Computer Graphics
Computing Face Normals ( Algebraic ) • For algebraic surfaces, compute • where 204481 Foundation of Computer Graphics
Vertex Normals • Each vertex has its own normal • primitive is Gouraud shaded basedon computed colors glBegin( GL_TRIANGLES ); glNormal3fv( n1 ); glVertex3fv( v1 ); glNormal3fv( n2 ); glVetrex3fv( v2 ); glNormal3fv( n3 ); glVertex3fv( v3 ); glEnd(); 204481 Foundation of Computer Graphics
Computing Vertex Normals (Algebraic ) • For algebraic surfaces, compute 204481 Foundation of Computer Graphics
Computing Vertex Normals ( Polygons ) • Need two things • face normals for all polygons • know which polygons share a vertex 204481 Foundation of Computer Graphics
Sending Normals to OpenGL glNormal3f( x, y, z ); • Use between glBegin() / glEnd() • Use similar to glColor*() 204481 Foundation of Computer Graphics
Normals and Scale Transforms • Normals must be normalized • non-unit length skews colors • Scales affect normal length • rotates and translates do not glEnable( GL_NORMALIZE ); 204481 Foundation of Computer Graphics
Why? • Lighting computations are really done in eye coordinates • this is why there are the projection and modelview matrix stacks • Lighting normals transformed by the inverse transpose of the ModelView matrix 204481 Foundation of Computer Graphics
Applying Illumination • With polygonal/triangular models: • Each facet has a constant surface normal • If the light is directional, the diffuse reflectance is constant across the facet • If the eyepoint is infinitely far away (constant V), the specular reflectance of a directional light is constant across the facet 204481 Foundation of Computer Graphics
Flat Shading • The simplest approach, flat shading, calculates illumination at a single point for each polygon: • If an object really is faceted, is this accurate? • No: • For point sources, the direction to light varies across the facet • For specular reflectance, direction to eye varies across the facet 204481 Foundation of Computer Graphics
Flat Shading • We can refine it a bit by evaluating the Phong lighting model at each pixel of each polygon, but the result is still clearly faceted: • To get smoother-looking surfaceswe introduce vertex normals at eachvertex • Usually different from facet normal • Used onlyfor shading (as opposed to what?) • Think of as a better approximation of the real surface that the polygons approximate (draw it) 204481 Foundation of Computer Graphics
Vertex Normals • Vertex normals may be • Provided with the model • Computed from first principles • Approximated by averaging the normals of the facets that share the vertex 204481 Foundation of Computer Graphics
Gouraud Shading • This is the most common approach • Perform Phong lighting at the vertices • Linearly interpolate the resulting colors over faces • This is what OpenGL does • Demo at http://www.cs.virginia.edu/~cs551/vrml/tpot.wrl • Does this eliminate the facets? 204481 Foundation of Computer Graphics
Phong Shading • Phong shading is not the same as Phong lighting, though they are sometimes mixed up • Phong lighting: the empirical model we’ve been discussing to calculate illumination at a point on a surface • Phong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixel • Same input as Gouraud shading • Usually very smooth-looking results: • But, considerably more expensive 204481 Foundation of Computer Graphics
Texture Mapping: Motivation • Scenes created with diffuse lighting look convincingly three-dimensional, but are flat, chalky, and “cartoonish” • Phong lighting lets us simulate materials like plastic and (to a lesser extent) metal, but scenes still seem very cartoonish and unreal • Big problem: polygons are too coarse-grained to usefully model fine surface detail • Solution: texture mapping 204481 Foundation of Computer Graphics
Texture Mapping: Motivation • Adding surface detail helps keep CG images from looking simple and sterile • Explicitly modeling this detail in geometry can be very expensive • Zebra stripes, wood grain, writing on a whiteboard • Texture mapping pastes images onto the surfaces in the scene, adding realistic fine detail without exploding the geometry 204481 Foundation of Computer Graphics
Texture Mapping: Examples 204481 Foundation of Computer Graphics
Texture Mapping: Fundamentals • A texture is typically a 2-D image • Image elements are called texels • Value stored at a texel affects surface appearance in some way • Example: diffuse reflectance, shininess, transparency… • The mapping of the texture to the surface determines the correspondence, i.e., how the texture lies on the surface • Mapping a texture to a triangle is easy (why?) • Mapping a texture to an arbitrary 3-D shape is more complicated (why?) 204481 Foundation of Computer Graphics
Texture Mapping: Rendering • Rendering uses the mapping: • Find the visible surface at a pixel • Find the point on that surface corresponding to that pixel • Find the point in the texture corresponding to that point on the surface • Use the parameters associated with that point on the texture to shade the pixel 204481 Foundation of Computer Graphics
Texture Mapping: Basics • We typically parameterize the texture as a function in (u, v) • For simplicity, normalize u & v to [0, 1] • Associate each triangle with a texture • Give each vertex of the triangle a texture coordinate (u, v) • For other points on the triangle, interpolate texture coordinate from the vertices • Much like interpolating color or depth • But there’s a catch... 204481 Foundation of Computer Graphics