Illumination and Shading Illumination and Shading z Illumination Models y Ambient y Diffuse y Attenuation y Specular Reflection z Interpolated Shading Models y Flat, Gouraud, Phong y Problems CS4451: Fall 2002 1
Illumination Models: Ambient Light z Simple illumination model I = k i z Use nondirectional lights I = I a k a z I a = ambient light intensity z k a = ambient-reflection coefficient z Uniform across surface Diffuse Light z Account for light position y Ignore viewer position z Proportional to cosq between N and L I = I p k d cosq = I p k d (N L) z Model: I = I a k a + I p k d (N L) CS4451: Fall 2002 2
Attenuation: Distance z f att models distance from light I = I a k a + f att I p k d (N L) z Realistic f att = 1/(d L2 ) z Hard to control, so OpenGL uses f att = 1/(c 1 + c 2 d L + c 3 d L2 ) Attenuation: Atmospheric (fog, haze) z z f and z b : near/far depth-cue plane z s f and s b : scale factors z I dc : depth cue color z Given z f > z 0 > z b interpolate s f > s 0 > s b z Adjust intensity I = s 0 I + (1 - s 0 )I dc CS4451: Fall 2002 3
Colored Lights (slightly different, but equivalent, to book) z O d : diffuse color y (O dr, O dg, O db ) z Compute for each component z i.e. red compenent is I R = I ar k a O dr + f att I pr k d O dr (N L) z Note: use O d for ambient and diffuse Specular Reflection: Phong Model z Account for viewer position y Create highlights z Based on cos n a = (R V) n L N R y Larger n, smaller highlight z k s : specular reflection coef. Q Q a V I = I a k a O d + f att I p [ k d O d (N L) + k s (R V) n ] CS4451: Fall 2002 4
Multiple Light Sources z Obvious summation over m lights: I = I a k a O d + S f atti I pi [ k d O d (N L i ) + k s (R i V) n ] 1 0 m Shading Models: Flat Shading z Compute one color for polygon y Use polygon normal in lighting eqs. z Every pixel is assigned same color z Fast and simple z Shade of polygons independent CS4451: Fall 2002 5
Gouraud Shading N 3 N 4 Navg N 1 N 2 z Compute vertex normals y Average normals of abutting polygons z Use vertex normal in lighting eqs. z Linearly interpolate vertex intensities y Along edges y Along scan lines V 1 V 2 A V is B V 4 V 3 CS4451: Fall 2002 6
Gouraud Shading z Often appears dull, chalky y Lacks accurate specular component x If included, will be averaged over entire polygon z Mach banding y Artifact at discontinuities in intensity or intensity slope CS4451: Fall 2002 7
Phong Shading z Linearly interpolate vertex normals y Compute lighting eqs. at each pixel x Normals must be backmapped to WC z Can use specular component CS4451: Fall 2002 8
CS4451: Fall 2002 9
Closeup: Flat, Gouraud, Phong Problems with Interpolated Shading z Polygonal silhouette z Perspective distortion V 1 V 2 A V is B V 4 V 3 CS4451: Fall 2002 10
Problems with Interpolated Shading z Scanline/orientation dependent y Creates temporal aliasing when used to render animation frames: =? 8 4 Problems with Interpolated Shading z Shared vertices A B C z Unrepresentative vertex normals y Missed specular highlights y Missed geometry CS4451: Fall 2002 11
Lighting, in practice z z z z Full lighting equation: I = I a k a O d + S f atti I pi [ k d O d (N L i ) + k s (R i V) n ] 1 0 m Ignore specular for now Each surface: O d, k a, k d, v i (i=0..n), N Each light: I a or d, f att (c 1, c 2, c 3 ), P L (position) At a given point z Start with ambient: I a k a O d y R/G/B using I ar, I ag, I ab, O dr, O dg, O db z For each Light, compute: f att I p k d O d (N L i ) y Position (P P ), normal (N P ) y L vector y d L y f att = 1/(c 1 + c 2 d L + c 3 d L2 ) y R/G/B using I pr, I pg, I pb, O dr, O dg, O db CS4451: Fall 2002 12
Light Intensity Values z I a, I d yrepresent intensity yhave R,G,B components ydo not need to fall in the 0..1 range! x Often need I d >1 x Final computed I 1 Specular z A light might have a diffuse and specular specification, say I s y Allow slightly different colors, more control x Remember, it s a hack anyway! z I s would have RGB parts, as with I a, I d z Illumination formula becomes I = I a k a O d + S f atti [I pdi k d O d (N L i ) + I psi k s (R i V) n ] 1 0 m CS4451: Fall 2002 13