Computer Graphics
Si Lu
Fall 2017
http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 11/06/2017
Computer Graphics Si Lu Fall 2017 - - PowerPoint PPT Presentation
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
http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 11/06/2017
2
3
n Mathematically: Vector that is perpendicular to the tangent plane
n Just “the normal vector” or “the normal” n Will use n or N to denote
transformation matrix
coordinates
n T T n T n p x T T n p x n p x n
t t t t t t
) ( ) ( : be must then normal new The : to equal be must normal transpose new The point. ed transform the is half hand right The ) ( : tangent ed transform a ith equation w he Consider t ) ( : this
form matrix a is There ) ( : ectors tangent v ar to perpedicul are vectors Normal
1 1 1 1
n The models are local because they don’t consider other
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.
n We are applying these computations at a particular point on a surface n We have a normal vector for that point
n Direct illumination from light sources n Diffuse and Specular reflections n (Very) Approximate effects of global lighting
n Shadows n Mirrors n Refraction n Lots of other stuff …
n Diffuse component for the amount of incoming light from a point source reflected equally in all directions n Specular component for the amount
in a mirror-like fashion n Ambient term to approximate light arriving via other surfaces
directions
n No dependence on viewing direction
n Angle of surface with respect to light source
be reflected
n Diffuse reflectance coefficient of the surface, kd
i dI
i dI
Where is the light? Which point is brightest (how is the normal at the brightest point related to the light)?
given incoming direction:
light position or direction Diffuse? Diffuse?
n Perceived intensity depends on the relationship between the viewing direction, V, and the mirror direction n Bright spot is called a specularity
n The specular reflectance coefficient, ks n The Phong Exponent, p, controls the apparent size of the specularity
p i sI
L R V
given incoming direction:
light position or direction Specular? Specular?
p i sI
L V N H
n Gross approximation to light bouncing around of all other surfaces n Modulated by ambient reflectance ka
p s d i a a
practitioners realize it
n k terms depend on wavelength, should compute for continuous spectrum
n r s r d r i r a r a r
, , , , ,
n Assume L is constant for all x n Good approximation if light is distant, such as sun
n Assume V is constant for all x n Rarely good, but only affects specularities
n Assume L is constant for all x n Good approximation if light is distant, such as sun n Generally called a directional light source
n Diffuse? n Specular?
n V(x) = ||c-x|| n Slightly expensive to compute
n Independent of which point is being lit n Use the view plane normal vector n Error depends on the nature of the scene
appearance of a surface
you would consider the “color” of a surface
n Also called diffuse reflectance coefficients
specularities
n Some systems do not let you specify this color separately
looks when not directly lit
n Normally the same as the diffuse color
n Changes one of the coefficients for the front or back side of a face (or both sides)
n Changes one of the properties of a light (intensities, positions, directions, etc) n There are 8 lights: GL_LIGHT0, GL_LIGHT1, …
n Changes one of the global light model properties (global ambient light, for instance)
n You must enable lights before they contribute to the image n You can enable and disable lights at any time
n You must enable lighting explicitly – it is off by default
n It’s expensive - turn it off by giving 0,0,0 as specular color of the lights
n If you use scaling transformations, must enable GL_NORMALIZE to keep normal vectors of unit length
n Where is the light coming from (the L vector)? n How much light is coming (the I values)?
n Point light source: Light from a specific point n Directional: Light from a specific direction 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)
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:
n 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): Glfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); Glfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position);
p
p L(x)
light light
n Requires a position: the location of the source n Requires a direction: the center axis of the light n Requires a cut-off: how broad the beam is n Requires and exponent: how the light tapers off at the edges
glLightfv(GL_LIGHT0, GL_POSITION, light_posn); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_dir); glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0); glLightfv(GL_LIGHT0, GL_SPOT_EXPONENT, 1.0);
cut-off directionD
n The point n The surface normal n The viewer location (or direction) n The light location (or direction)
p s d i a a
point and apply to whole polygon
n OpenGL uses one of the vertices
n Fast - one shading computation per polygon
n Inaccurate n What are the artifacts?
n Fast: incremental calculations when rasterizing n Much smoother - use same normal every time a vertex is used for a face
n What are the artifacts? n Is it accurate?
n High quality, narrow specularities
n Expensive n Still an approximation for most surfaces
n Controls how colors are assigned to pixels n glShadeModel(GL_SMOOTH) interpolates between the colors at the vertices (the default, Gouraud shading) n glShadeModel(GL_FLAT) uses a constant color across the polygon
n Also requires fragment shaders on programmable graphics hardware
35