Computer Graphics Si Lu Fall 2017 http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 11/06/2017
Last time o Hidden Surface Removal 2
Today o Lighting and Shading o Project 2 o Will publicize several times in the final week of classes when you can get your project graded n Demo your program to the instructor in person o Bring your own laptop or on a CS Windows Lab Machine n Latest time to grade o 5:00 pm, Friday, December 1, 2017 n No late submission! 3
Where We Stand o So far we know how to: n Transform between spaces n Draw polygons n Decide what’s in front o Next n Deciding a pixel’s intensity and color
Normal Vectors o The intensity of a surface depends on its orientation with respect to the light and the viewer o The surface normal vector describes the orientation of the surface at a point n Mathematically: Vector that is perpendicular to the tangent plane of the surface Just “the normal vector” or “the normal” n Will use n or N to denote n o Normals are either supplied by the user or automatically computed
Transforming Normal Vectors o Normal vectors are directions Normal vectors are perpedicul ar to tangent v ectors : n ( x p ) 0 t There is a matrix form of this : n ( x p ) 0 t 1 Consider t he equation w ith a transform ed tangent : n T T ( x p ) 0 The right hand half is the transform ed point. t 1 The new transpose normal must be equal to : n T t 1 t 1 t The new normal must then be : ( n T ) ( T ) n o To transform a normal, multiply it by the inverse transpose of the transformation matrix o Recall, rotation matrices are their own inverse transpose o Don’t include the translation! Use (n x ,n y ,n z ,0) for homogeneous coordinates
Local Shading Models o Local shading models provide a way to determine the intensity and color of a point on a surface The models are local because they don’t consider other n objects n We use them because they are fast and simple to compute n They do not require knowledge of the entire scene, only the current piece of surface. o For the moment, assume: We are applying these computations at a particular point on a n surface n We have a normal vector for that point
Local Shading Models o What they capture: n Direct illumination from light sources n Diffuse and Specular reflections n (Very) Approximate effects of global lighting What they don’t do: o n Shadows Mirrors n Refraction n Lots of other stuff … n
“Standard” Lighting Model o Consists of three terms linearly combined: Diffuse component for the amount of n incoming light from a point source reflected equally in all directions n Specular component for the amount of light from a point source reflected in a mirror-like fashion Ambient term to approximate light n arriving via other surfaces
Diffuse Illumination L k d I ( N ) i o Incoming light, I i , from direction L , is reflected equally in all directions n No dependence on viewing direction o Amount of light reflected depends on: n Angle of surface with respect to light source Actually, determines how much light is collected by the surface, to then o be reflected n Diffuse reflectance coefficient of the surface, k d L k d I max( N , 0 ) Don’t want to illuminate back side. Use o i
Diffuse Example Where is the light? Which point is brightest (how is the normal at the brightest point related to the light)?
Illustrating Shading Models • Show the polar graph of the amount of light leaving for a given incoming direction: Diffuse? • Show the intensity of each point on a surface for a given light position or direction Diffuse?
L V Specular Reflection R (Phong Reflectance Model) R p k s I ( V ) i o Incoming light is reflected primarily in the mirror direction, R Perceived intensity depends on the relationship between the n viewing direction, V , and the mirror direction Bright spot is called a specularity n o Intensity controlled by: The specular reflectance coefficient, k s n n The Phong Exponent , p , controls the apparent size of the specularity o Higher p , smaller highlight
Specular Example
Illustrating Shading Models • Show the polar graph of the amount of light leaving for a given incoming direction: Specular? • Show the intensity of each point on a surface for a given light position or direction Specular?
Alternative Specular Reflection Model L V H L V / L V H N p k s I ( H N ) i o Compute based on normal vector and “halfway” vector, H
Putting It Together p I k I I k ( L N ) k ( H N ) a a i d s o Global ambient intensity, I a : n Gross approximation to light bouncing around of all other surfaces n Modulated by ambient reflectance k a Just sum all the terms o If there are multiple lights, sum contributions from each light o o Several variations, and approximations …
Color n I k I I k ( L N ) k ( H N ) r a , r a , r i , r d , r s , r o Do everything for three colors, r, g and b Note that some terms (the expensive ones) are constant o Using only three colors is an approximation, but few graphics o practitioners realize it n k terms depend on wavelength, should compute for continuous spectrum
Approximations for Speed o The viewer direction, V , and the light direction, L , depend on the surface position being considered, x o Distant light approximation: n Assume L is constant for all x n Good approximation if light is distant, such as sun o Distant viewer approximation n Assume V is constant for all x n Rarely good, but only affects specularities
Distant Light Approximation o Distant light approximation: Assume L is constant for all x n Good approximation if light is distant, such as sun n n Generally called a directional light source o What aspects of surface appearance are affected by this approximation? Diffuse? n n Specular?
Distant Viewer Approximation o Specularities require the viewing direction: V(x) = || c-x || n Slightly expensive to compute n o Distant viewer approximation uses a global V n Independent of which point is being lit Use the view plane normal vector n Error depends on the nature of the scene n o Is the diffuse component affected?
Describing Surfaces o The various parameters in the lighting equation describe the appearance of a surface o (k d,r ,k d,g ,k d,b ) : The diffuse color , which most closely maps to what you would consider the “color” of a surface n Also called diffuse reflectance coefficients (k s,r ,k s,g ,k s,b ) : The specular color, which controls the color of o specularities n Some systems do not let you specify this color separately o (k a,r ,k a,g ,k a,b ) : The ambient color, which controls how the surface looks when not directly lit Normally the same as the diffuse color n
OpenGL Commands (1) o glMaterial{if}(face, parameter, value) n Changes one of the coefficients for the front or back side of a face (or both sides) o glLight{if}(light, property, value) Changes one of the properties of a light (intensities, positions, n directions, etc) n There are 8 lights: GL_LIGHT0, GL_LIGHT1, … o glLightModel{if}(property, value) n Changes one of the global light model properties (global ambient light, for instance) glEnable(GL_LIGHT0) enables GL_LIGHT0 o n You must enable lights before they contribute to the image n You can enable and disable lights at any time
OpenGL Commands (2) o glEnable(GL_LIGHTING) turns on lighting n You must enable lighting explicitly – it is off by default o Don’t use specular intensity if you don’t have to n It’s expensive - turn it off by giving 0,0,0 as specular color of the lights o Don’t forget normals n If you use scaling transformations, must enable GL_NORMALIZE to keep normal vectors of unit length Many other things to control appearance o
Light Sources o Two aspects of light sources are important for a local shading model: Where is the light coming from (the L vector)? n n How much light is coming (the I values)? o Various light source types give different answers to the above questions: n Point light source : Light from a specific point Directional : Light from a specific direction n n Spotlight : Light from a specific point with intensity that depends on the direction n Area light : Light from a continuum of points (later in the course)
Point and Directional Sources p -x o Point light: light L(x) p -x light n The L vector depends on where the surface point is located n Must be normalized - slightly expensive n To specify an OpenGL light at 1,1,1: Glfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); o Directional light: L(x) = L light The L vector does not change over points in the world n OpenGL light traveling in direction 1,1,1 ( L is in opposite direction): n Glfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position);
Recommend
More recommend