CS-184: Computer Graphics Lecture #8: Shading Prof. James O Brien University of California, Berkeley V2006-S-08-2.0 Today Local Illumination & Shading The BRDF Simple diffuse and specular approximations Shading interpolation: flat, Gouraud, Phong Some miscellaneous tricks Normal Vectors 2
Local Shading Local: consider in isolation 1 light 1 surface The viewer Recall: lighting is linear Almost always... Counter example: photochromatic materials 3 Local Shading Examples of non-local phenomena Shadows Reflections Refraction Indirect lighting 4
The BRDF The Bi-directional Reflectance Distribution Function Given! =!(" V," L ) Surface material =!(v,l,n) Incoming light direction Direction of viewer Orientation of surface Return: fraction of light that reaches the viewer We ll worry about physical units later... 5 The BRDF!(v,l,n) ˆl ˆn ˆv Spatial variation capture by the material Frequency dependent Typically use separate RGB functions Does not work perfectly Better:! =!(" V," L,# in,# out ) 6
Obtaining BRDFs Measure from real materials Images from Marc Levoy 7 Obtaining BRDFs Measure from real materials Computer simulation Simple model + complex geometry Derive model by analysis Make something up 8
Beyond BRDFs The BRDF model does not capture everything e.g. Subsurface scattering (BSSRDF) Images from Jensen et. al, SIGGRAPH 2001 9 Beyond BRDFs The BRDF model does not capture everything e.g. Inter-frequency interactions! =!(" V," L,# in,# out ) This version would work... 10
A Simple Model Approximate BRDF as sum of A diffuse component A specular component A ambient term + + = 11 Diffuse Component Lambert s Law Intensity of reflected light proportional to cosine of angle between surface and incoming light direction Applies to diffuse, Lambertian, or matte surfaces Independent of viewing angle Use as a component of non-lambertian surfaces 12
Diffuse Component k d I(ˆl ˆn) Comment about two-side lighting in text is wrong... max(k d I(ˆl ˆn),0) 13 Diffuse Component Plot light leaving in a given direction: Plot light leaving from each point on surface 14
Specular Component Specular component is a mirror-like reflection Phong Illumination Model A reasonable approximation for some surfaces Fairly cheap to compute Depends on view direction 15 Specular Component k s I(ˆr ˆv) p k s I max(ˆr ˆv,0) p L N V R 16
Specular Component Computing the reflected direction ˆr = ˆl + 2(ˆl ˆn)ˆn n l r θ n cos θ n cos θ ĥ = ˆl + ˆv ˆl + ˆv l n ω h -l e 17 Specular Component Plot light leaving in a given direction: Plot light leaving from each point on surface 18
Specular Component Specular exponent sometimes called roughness n=1 n=2 n=4 n=8 n=16 n=32 n=64 n=128 n=256 19 Ambient Term Really, its a cheap hack Accounts for ambient, omnidirectional light Without it everything looks like it s in space 20
Summing the Parts R = k a I + k d I max(ˆl ˆn,0) + k s I max(ˆr ˆv,0) p + + = Recall that the RGB in practice k? Sum over all lights are by wavelength 21 Anisotropy 22
Metal -vs- Plastic 23 Metal -vs- Plastic 24
Other Color Effects 25 Other Color Effects Figure 9: Top: Colored Phong-shaded spheres with edge lines and highlights. Bottom: Colored spheres shaded with hue and luminance shift, including edge lines and highlights. Note: In the first Phong shaded sphere (violet), the edge lines disappear, but are visible in the corresponding hue and luminance shaded violet sphere. In the last Phong shaded sphere (white), the highlight vanishes, but is noticed in the corresponding hue and luminance shaded white sphere below it. The spheres in the second row also retain their color name. Figure 9: Top: Colored Phong-shaded spheres with edge lines and highlights. Bottom: Colored spheres shaded with hue and luminance shift, including edge lines and highlights. Note: In the first Phong shaded sphere (violet), the edge lines disappear, but are visible in the corresponding hue and luminance shaded violet sphere. In the last Phong shaded sphere (white), the highlight vanishes, but is noticed in the corresponding hue and luminance shaded white sphere below it. The spheres in the second row also retain their color name. darken pure blue to yellow Figure 10: Left to Right: a) Phong shaded object. b) New metal-shaded object without edge lines. c) New metal-shaded object with edge lines. d) New metal-shaded object with a cool-to-warm shift. Figure 10: Left to Right: a) Phong shaded object. b) New metal-shaded object without edge lines. c) New metal-shaded object with edge lines. d) New metal-shaded object with a cool-to-warm shift. select pure black to object color + = is pure black an fuse shading where would look much like traditional diffuse sha ject would vary in luminance, including wh would really like is a compromise between transitions will result in a combination of to and a cool-to-warm undertone, an effect w combining pigments. We can simulate unde between the blue/yellow and black/object-co final tone Figure 2: How the tone is created for a pure red object by summing a blue-to-yellow and a dark-red-to-red tone. Figure 11: Left to Right: a) Phong model for colored object. b) New shading model with highlights, cool-to-warm hue shift, and without edge lines. c) New model using edge lines, highlights, and cool-to-warm hue shift. d) Approximation using conventional Phong shading, two colored lights, and edge lines. Figure 11: Left to Right: a) Phong model for colored object. b) New shading model with highlights, cool-to-warm hue shift, and without edge lines. c) New model using edge lines, highlights, and cool-to-warm hue shift. d) Approximation using conventional Phong shading, two colored lights, and edge lines. created by adding grey to a certain color they are called tones [2]. Such tones vary in hue but do not typically vary much in luminance. When the complement of a color is used to create a color scale, they are also called tones. Tones are considered a crucial concept to illustrators, and are especially useful when the illustrator is restricted to a small luminance range [12]. Another quality of color used by artists is the temperature of the color. The temperature of a color is defined as being warm (red, orange, and yellow), cool (blue, violet, and green), or temperate (red-violets and yellow-greens). The depth cue comes from the perception that cool recede while Images from Gooch et.colors al, 1998 warm colors advance. In addition, object colors change tempera26 ture in sunlit scenes because cool skylight and warm sunlight vary in relative contribution across the surface, so there may be ecological reasons to expect humans to be sensitive to color temperature variation. Not only is the temperature of a hue dependent upon the hue itself, but this advancing and receding relationship is effected by proximity [4]. We will use these techniques and their psychophysical relationship as the basis for our model. We can generalize the classic computer graphics shading model ) of Equato experiment with tones by using the cosine term ( and : tion 1 to blend between two RGB colors, Plugging these values into Equation 2 leave rameters:,,, and. The values for an strength of the overall temperature shift, and will determine the prominence of the object of the luminance shift. Because we want to ing which will visually interfere with black supply intermediate values for these consta resulting tone for a pure red object is shown and Substituting the values for into the tone Equation 2 results in shading middle luminance range as desired. Figure 7,, and. To show t not crucial to appropriate appearance, the s,, Figure 8 with Figure 5, subtleties of shape in the claws a and 8. The model is appropriate for a range of o ditional shading and the new tone-based sh set of spheres in Figure 9. Note that with th objects retain their color name so colors ca entiate objects like countries on a political m used do not interfere with the clear percept and white highlights.
Measured BRDFs BRDFs for automotive paint Images from Cornell University Program of Computer Graphics 27 Measured BRDFs BRDFs for aerosol spray paint Images from Cornell University Program of Computer Graphics 28
Measured BRDFs BRDFs for house paint Images from Cornell University Program of Computer Graphics 29 Measured BRDFs BRDFs for lucite sheet Images from Cornell University Program of Computer Graphics 30
Details Beget Realism The computer generated look is often due to a lack of fine/subtle details... a lack of richness. From bustledress.com 31 Direction -vs- Point Lights For a point light, the light direction changes over the surface For distant light, the direction is constant Similar for orthographic/perspective viewer 32
Falloff Physically correct: 1/r 2 light intensify falloff Tends to look bad (why?) Not used in practice Sometimes compromise of 1/r used 33 Spot and Other Lights Other calculations for useful effects Spot light Only light certain objects Negative lights etc. 34
Surface Normals The normal vector at a point on a surface is perpendicular to all surface tangent vectors For triangles normal given by right-handed cross product 35 Flat Shading Use constant normal for each triangle (polygon) Polygon objects don t look smooth Faceted appearance very noticeable, especially at specular highlights Recall mach bands... 36
Smooth Shading Compute average normal at vertices Interpolate across polygons Use threshold for sharp edges Vertex may have different normals for each face 37 Gouraud Shading Compute shading at each vertex Interpolate colors from vertices Pros: fast and easy, looks smooth Cons: terrible for specular reflections Flat Gouraud Note: Gouraud was hardware rendered... 38
Phong Shading Compute shading at each pixel Interpolate normals from vertices Pros: looks smooth, better speculars Cons: expensive Gouraud Phong Note: Gouraud was hardware rendered... 39 Transforming Normals Normals are directions But they must maintain underlaying geometric property A bit of manipulation ˆn (a b) = 0 ˆn T (a b) = 0 ˆn T new(ta Tb) = 0 ˆn T newt(a b) = 0 ˆn T T 1 T(a b) = 0 ˆn new = T Tˆn 40
Transforming Normals Special transformation rule for normals ˆn new = T Tˆn Note: A rotation is its own inverse transpose 41 Depth Distortion Recall depth distortion from perspective Interpolating in screen space different than in world Ok, for shading (mostly) Bad for texture Half way in world space World Screen Half way in screen space 42
Depth Distortion S 1 = P 1 /h 1 P 1 P 4 S 4 = P 4 /h 4 S 3 = P 3 /h 3 S 2 = P 2 /h 2 P 2 P 3 43 42 Depth Distortion S 1 = P 1 /h 1 P 1 P 4 S 4 = P 4 /h 4 S 3 = P 3 /h 3 S 2 = P 2 /h 2 X = i S i b i P 2 P 3 Q = P i a i i We know the S i, P i, and b i, but not the a i. 44 42
Depth Distortion S 1 = P 1 /h 1 P 1 P 4 S 4 = P 4 /h 4 S 3 = P 3 /h 3 P 2 P 3 S 2 = P 2 /h X = S 2 i b i Q = P i i a i i X = Q/h = P i a i / h j a j i j 45 42 Depth Distortion S 1 = P 1 /h 1 P 1 P 4 S 4 = P 4 /h 4 S 3 = P 3 /h 3 P 2 P 3 S 2 = P 2 /h X = S 2 i b i Q = P i i a i i S i b i = P i a i / h j a j i i j 46 42
Depth Distortion S 1 = P 1 /h 1 P 1 P 4 S 4 = P 4 /h 4 S 3 = P 3 /h 3 P 2 P 3 S 2 = P 2 /h X = S 2 i b i Q = P i i a i i P i b i /h i = P i a i / h j a j i i j 47 42 Depth Distortion Independent of given vertex locations. P i b i /h i = P i a i / h j a j i i j b i /h i = a i / h j a j i j 48 42
Depth Distortion Linear equations in the. a i b i /h i = a i / h j a j j h j a j b i /h i a i = 0 j i i 49 42 Depth Distortion Linear equations in the. a i Not invertible so add some extra constraints. h j a j b i /h i a i = 0 j a i = i i b i = 1 i 50
Depth Distortion For a line: a 1 = h 2 b i /(b 1 h 2 + h 1 b 2 ) For a triangle: a 1 = h 2 h 3 b 1 /(h 2 h 3 b 1 + h 1 h 3 b 2 + h 1 h 2 b 3 ) Obvious Permutations for other coefficients. 51