Ambient reflection Phong reflection is a local illumination model. It only considers the reflection of light that directly comes from the light source. It does not compute secondary reflection of light that is being reflected at one object and indirectly illuminates another object. To account for secondary reflection, a general light is added that distributes homogeneously through the entire 3D scene. This is called ambient reflection. Ambient light models undirected light from an infinitely large light source. 320322: Graphics and Visualization 407
Ambient reflection The light intensity I a of the ambient light source is distributed constantly throughout the scene. The reflected ambient light I at a surface point can be written as I = k a I a where k a is the ambient reflection coefficient. The ambient reflection coefficient is a constant out of the range [0,1]. It represents the material property of the illuminated object. 320322: Graphics and Visualization 408
Ambient reflection As ambient lighting is not directed, uni-colored and uni-material objects still appear in one color. Still, only the silhouettes can be perceived. The color of the object depends on the amount of reflected light defined by the reflection coefficient. 320322: Graphics and Visualization 409
Ambient reflection Ambient reflection with different reflection coefficients: 320322: Graphics and Visualization 410
Diffuse reflection Diffuse reflection denotes light scattering at a dull surface. The incoming directional light is reflected uniformly in each direction. The intensity of the reflected light is independent of the viewing angle. It depends on the direction of the incoming light ray. 320322: Graphics and Visualization 411
Diffuse reflection Lambert s law: The reflected light intensity I at a point p on a surface is proportional to cos θ, where θ is the angle between the vector l pointing from p to the light source and the surface normal n in point p. 320322: Graphics and Visualization 412
Diffuse reflection The reflected diffuse light I at a surface point p is given by I = I P k d cosθ = I P k d (n l) where I P is the intensity of the diffuse light source and k d is the diffuse reflection coefficient (and assuming that l is normalized). The diffuse reflection coefficient is a constant out of the range [0,1] and represents the material property of the illuminated object. 320322: Graphics and Visualization 413
Diffuse reflection This model assumes that the light source sends out directed light and is of infinitely small extent (point light source). Obviously, I=0 if n l < 0. Taking this into account, we should write: I = I P k d max(n l,0) 320322: Graphics and Visualization 414
Diffuse reflection Attenuation: Light intensity that spreads from a light source with finite extent decreases with increasing distance r P to the light source. We need to add an attenuation factor f att (r P ). We obtain: I = I P k d f att (r P ) max(n l,0). Physical law: f att (r P ) ~ 1/r P2. In practice, we use: f att (r P ) = min (1/(c 0 +c 1 r P + c 2 r P2 ),1) with real constants c 0,c 1, and c 2. 320322: Graphics and Visualization 415
Diffuse reflection 320322: Graphics and Visualization 416
Diffuse reflection Diffuse reflection with different reflection coefficients: 320322: Graphics and Visualization 417
Specular reflection Specular reflection models reflection at shiny surfaces. It adds highlights to the illumination. Phong s specular reflection model is based on perfect mirror reflection of light rays: r: direction of reflection rule: α = β 320322: Graphics and Visualization 418
Specular reflection Specular reflection depends on viewpoint: Specular reflection is highest, if viewpoint is in direction r. 320322: Graphics and Visualization 419
Phong s model: Specular reflection The light intensity I of reflected specular light is dependent on cos α, where α is the angle between the direction of the reflected light ray r and the direction v from the surface point to the viewpoint. 320322: Graphics and Visualization 420
Specular reflection Phong s model: I = I P k s f att (r P ) cos n α = I P k s f att (r P ) (r v) n where k s is the specular reflection coefficient and n is the specular reflection exponent. (and assuming that v is normalized). The specular reflection coefficient is a constant out of the range [0,1]. The specular reflection exponent is a constant natural number. They represents the material property of the illuminated object. 320322: Graphics and Visualization 421
Specular reflection The influence of the specular reflection exponent: 320322: Graphics and Visualization 422
Specular reflection Specular reflection with different reflection coefficients: 320322: Graphics and Visualization 423
Phong reflection model Putting it all together: Considering multiple point light sources P i, the Phong reflection model computes the reflected light intensity 320322: Graphics and Visualization 424
Phong reflection model Thederivedformulaisappliedfora certain wavelength of the light. It has to be applied for light of all wavelengths. Using the RGB color model, we compute the reflection independently for each of the three color channels. 320322: Graphics and Visualization 425
Phong reflection model 320322: Graphics and Visualization 426
How OpenGL Simulates Lights Phong lighting model Computed at vertices Lighting contributors Surface material properties Light properties Lighting model properties 320322: Graphics and Visualization 427
Surface Normals Normals define how a surface reflects light glnormal3f( x, y, z ) Current normal is used to compute vertex color Use unit normals for proper lighting scaling affects a normal s length glenable( GL_NORMALIZE ) 320322: Graphics and Visualization 428
Material Properties In addition to the ambient, diffuse, and specular reflection, OpenGL also allows a surface to emit light. The emitted light is constant and is added to the reflected component. Emitting surfaces do not affect other objects, i.e., they do not appear as light sources. 320322: Graphics and Visualization 429
Material Properties Define the surface properties of a primitive glmaterialfv( face, property, value ); GL_DIFFUSE GL_SPECULAR GL_AMBIENT GL_EMISSION GL_SHININESS Diffuse refl. coeff. Specular refl. coeff. Ambient refl. coeff. Emission Specular refl. exponent separate materials for front and back of a face 320322: Graphics and Visualization 430
Light Properties gllightfv( light, property, value ); light specifies which light is affected multiple lights, starting with GL_LIGHT0 glgetintegerv( GL_MAX_LIGHTS, &n ); properties colors position and type attenuation 320322: Graphics and Visualization 431
Light Colors Light color properties GL_AMBIENT GL_DIFFUSE GL_SPECULAR 320322: Graphics and Visualization 432
Types of Lights OpenGL supports two types of Lights Local (Point) light sources Infinite (Directional) light sources Type of light controlled by w coordinate w = 0 w 0 Infinite Light directed along Local Light positioned at ( x y z) ( ) x y z w w w 320322: Graphics and Visualization 433
Attenuation Light attenuation decrease light intensity with distance GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION f i = k c + k l 1 d + k q d 2 320322: Graphics and Visualization 434
Turning on the Lights Flip each light s switch glenable( GL_LIGHTn ); Turn on the power glenable( GL_LIGHTING ); 320322: Graphics and Visualization 435
Light & Material 320322: Graphics and Visualization 436
Advanced Lighting Features Spotlights localize lighting affects GL_SPOT_DIRECTION GL_SPOT_CUTOFF GL_SPOT_EXPONENT 320322: Graphics and Visualization 437