Illumination, Lighting and Shading Model Pradondet Nilagupta Dept. of Computer Engineering
Download ReportTranscript Illumination, Lighting and Shading Model Pradondet Nilagupta Dept. of Computer Engineering
Illumination, Lighting and Shading Model Pradondet Nilagupta Dept. of Computer Engineering Kasetsart University 204481 Foundation of Computer Graphics May 25, 2016 1 Definitions (1/2) Illumination: the transport of energy (in particular, the luminous flux of visible light) from light sources to surfaces & points Note: includes direct and 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 May 25, 2016 2 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 May 25, 2016 3 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 May 25, 2016 4 Lighting Model Component Material Properties Surface Normals Light Properties used to describe an objects reflected colors used to describe a lights color emissions Light Model Properties “global” lighting parameters 204481 Foundation of Computer Graphics May 25, 2016 5 Components of Illumination Light sources (or emitters) Spectrum of emittance (i.e, color of the light) Geometric attributes Surface properties Reflectance spectrum (i.e., color of the surface) Geometric attributes Position Direction Shape Position Orientation Micro-structure Directional attenuation 204481 Foundation of Computer Graphics May 25, 2016 6 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) 204481 Foundation of Computer Graphics Ireflected = kambient Iambient May 25, 2016 7 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 May 25, 2016 8 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 May 25, 2016 9 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 May 25, 2016 10 Reflection Ambient Reflections Diffuse Reflection Specular Reflections 204481 Foundation of Computer Graphics May 25, 2016 11 Ambient Reflections Color of an object when not directly illuminated Think about walking into a room with the curtains closed and lights off I a g a li a ma i 204481 Foundation of Computer Graphics May 25, 2016 12 Diffuse Reflections Color of an object when directly illuminated l often referred to as base color The angle between the surface normal and the incoming light is the angle of incidence: Idiffuse = kd Ilight cos 204481 Foundation of Computer Graphics n In practice we use vector arithmetic: Idiffuse = kd Ilight (n • l) May 25, 2016 13 Specular Reflections v Shiny surfaces exhibit specular reflection h l n̂ Polished metal Glossy car finish A light shining on a specular surface causes a bright spot known as a specular highlight I s lis ms nˆ hˆ i hˆ 204481 Foundation of Computer Graphics May 25, 2016 s 1 2 lˆ vˆ 14 Phong Lighting Model Using surface normal OpenGL’s lighting model based on Phong’s I Ia Id Is 204481 Foundation of Computer Graphics May 25, 2016 15 OpenGL Material Properties GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_SHININESS GL_EMISSION 204481 Foundation of Computer Graphics May 25, 2016 16 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 May 25, 2016 17 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 May 25, 2016 18 Computing Face Normals ( Polygons ) We’re using only planar polygons Can easily compute the normal to a plane use a cross product b a 204481 Foundation of Computer Graphics xˆ yˆ a b ax a y bx by a b nˆ a b May 25, 2016 zˆ az bz 19 Computing Face Normals ( Algebraic ) For algebraic surfaces, compute f f f n ( x, y, z ) x y z x, y, z n nˆ n where x y z n 1 n 204481 Foundation of Computer Graphics x i yi z i i May 25, 2016 20 Vertex Normals Each vertex has its own normal primitive is Gouraud shaded based on computed colors glBegin( GL_TRIANGLES ); glNormal3fv( n1 ); glVertex3fv( v1 ); glNormal3fv( n2 ); glVetrex3fv( v2 ); glNormal3fv( n3 ); glVertex3fv( v3 ); glEnd(); 204481 Foundation of Computer Graphics May 25, 2016 21 Computing Vertex Normals (Algebraic ) For algebraic surfaces, compute f f f n ( x, y, z ) x y z x, y, z n nˆ n 204481 Foundation of Computer Graphics May 25, 2016 22 Computing Vertex Normals ( Polygons ) Need two things face normals for all polygons know which polygons share a vertex nˆv m nˆ i i 204481 Foundation of Computer Graphics May 25, 2016 23 Sending Normals to OpenGL glNormal3f( x, y, z ); Use between glBegin() / glEnd() Use similar to glColor*() 204481 Foundation of Computer Graphics May 25, 2016 24 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 May 25, 2016 25 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 May 25, 2016 26 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 May 25, 2016 27 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 May 25, 2016 28 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 surfaces we introduce vertex normals at each vertex Usually different from facet normal Used only for 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 May 25, 2016 29 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 May 25, 2016 30 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 May 25, 2016 31 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 May 25, 2016 32 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 May 25, 2016 33 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 May 25, 2016 34 Texture Mapping: Examples 204481 Foundation of Computer Graphics May 25, 2016 35 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 May 25, 2016 36 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 May 25, 2016 37 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 May 25, 2016 38