Lighting and Shading Comp 770 Lecture Notes Spring

  • Slides: 42
Download presentation
Lighting and Shading Comp 770 Lecture Notes Spring 2009

Lighting and Shading Comp 770 Lecture Notes Spring 2009

Overview u Last time, we covered light-matter interaction. u Now, apply it to rendering.

Overview u Last time, we covered light-matter interaction. u Now, apply it to rendering. u Outline: § § § Lighting and shading. Lighting models. Shading methods.

Those Were the Days u (Or: how not to motivate a 21 st century

Those Were the Days u (Or: how not to motivate a 21 st century computer graphics paper. ) l “In trying to improve the quality of the synthetic images, we do not expect to be able to display the object exactly as it would appear in reality, with texture, overcast shadows, etc. We hope only to display an image that approximates the real object closely enough to provide a certain degree of realism. ” – Bui Tuong Phong, 1975

Lighting vs. Shading u Commonly misused terms. u What’s the difference?

Lighting vs. Shading u Commonly misused terms. u What’s the difference?

Lighting vs. Shading u Commonly misused terms. u What’s the difference? u Lighting designates

Lighting vs. Shading u Commonly misused terms. u What’s the difference? u Lighting designates the interaction between materials and light sources, as in last lecture ( i. e. Physics). u Shading is the process of determining the color of a pixel (i. e. Computer Graphics). § § Usually determined by lighting. Could use other methods: random color,

Lighting Models u Will § Lambert. l § Purely diffuse surfaces. Phong. l §

Lighting Models u Will § Lambert. l § Purely diffuse surfaces. Phong. l § discuss 3: Adds perceptually-based specular term. Torrance-sparrow: l Provides a physical approximation.

Lambert Lighting Model u Sometimes mistakenly attributed to Gouraud. § § Gouraud didn’t introduce

Lambert Lighting Model u Sometimes mistakenly attributed to Gouraud. § § Gouraud didn’t introduce a new lighting model, just a shading method. Used approximations from Warnock and Romney. l Both based on Lambert’s cosine law.

Lambert’s Cosine Law u The reflected luminous intensity in any direction from a perfectly

Lambert’s Cosine Law u The reflected luminous intensity in any direction from a perfectly diffusing surface varies as the cosine of the angle between the direction of incident light and the normal vector of the surface. u Intuitively: cross-sectional area of the “beam” intersecting an element of surface area is smaller for greater angles with the normal.

Lambert’s Cosine Law u Ideally § u Id § diffuse surfaces obey cosine law.

Lambert’s Cosine Law u Ideally § u Id § diffuse surfaces obey cosine law. Often called Lambertian surfaces. = kd Iincident cos = kd Iincident (N·L). kd is the diffuse reflectance of the material. l I N Wavelength dependent, so usually specified as a color.

Phong Lighting Model u Phong adds specular highlights. u His original formula for the

Phong Lighting Model u Phong adds specular highlights. u His original formula for the specular term: § W(i)[cos s ]n l l s is the angle between the view and specular reflection directions. “W(i) is a function which gives the ratio of the specular reflected light and the incident light as a function of the incident angle i. ” • Ranges from 10 to 80 percent. l “n is a power which models the specular reflected light for each material. ” • Ranges from 1 to 10.

Phong Lighting Model u More recent formulations are slightly different. § Replace W(i) with

Phong Lighting Model u More recent formulations are slightly different. § Replace W(i) with a constant ks, independent of the incident direction. l What do we lose when we do this? ks Iincident cosn = ks Iincident (V·R)n. § Is= V is the view direction. l R is the specular reflection direction. l

Blinn-Phong Model u Popular variation of Phong model. u Uses the halfway vector, H.

Blinn-Phong Model u Popular variation of Phong model. u Uses the halfway vector, H. L u Is = ks Iincident (N·H)n. N H § H = L+V / | L+V | u What are the advantages? V

Blinn-Phong Model u Popular variation of Phong model. u Uses the halfway vector, H.

Blinn-Phong Model u Popular variation of Phong model. u Uses the halfway vector, H. L u Is = ks Iincident (N·H)n. N H § H = L+V / | L+V | u Faster V to compute than reflection vector. u Still view-dependent since H depends on V.

Blinn-Phong Highlights u Does using N. H vs. R. V affect highlights? § §

Blinn-Phong Highlights u Does using N. H vs. R. V affect highlights? § § u Is Yes, the highlights “spread”. Why? this bad?

Blinn-Phong Highlights u Does using N. H vs. R. V affect highlights? § §

Blinn-Phong Highlights u Does using N. H vs. R. V affect highlights? § § u Is § Yes, the highlights “spread”. Why? this bad? Not really, for two reasons. Can always just adjust the exponent. l Phong and Blinn-Phong are not physically based, so it doesn’t really matter! l

Torrance-Sparrow Model u Introduced by Torrance and Sparrow in 1967 as a theoretical model.

Torrance-Sparrow Model u Introduced by Torrance and Sparrow in 1967 as a theoretical model. u Introduced to CG community by Blinn in 1977. § same paper as “Halfway Vector” (Blinn-Phong). u Attempts to provide a more physical model for specular reflections from real surfaces. § § Points out that intensity of specular highlights is dependent on the incident direction relative to normal. Phong attempted to model this with w(i) factor?

Torrance-Sparrow Model u Back to micro facets. u Assumptions: § § Diffuse component comes

Torrance-Sparrow Model u Back to micro facets. u Assumptions: § § Diffuse component comes from multiple reflections between facets and from internal scattering. Specular component of surface comes from facets oriented in direction of H.

Torrance-Sparrow Model u Is = § § § DGF / (N·V) D is the

Torrance-Sparrow Model u Is = § § § DGF / (N·V) D is the distribution function of the micro facet directions on the surface. G is the amount that facets shadow and mask each other. F is the Fresnel reflection law.

D: Micro Facet Distribution u T-S § § § used simple Gaussian distribution: -(

D: Micro Facet Distribution u T-S § § § used simple Gaussian distribution: -( )2 D=e = deviation angle from halfway vector, H. = standard deviation. l Large values = dull, small values = shiny

Denominator u Intensity proportional to number of facets in H direction. § So, must

Denominator u Intensity proportional to number of facets in H direction. § So, must account for fact that observer sees more surface area when surface is tilted. l § Change in area proportional to cosine of tilt angle. Hence, N·V in denominator.

G: Geometrical Attenuation Factor u Remember micro facet shadowing and masking? shadow u Blinn

G: Geometrical Attenuation Factor u Remember micro facet shadowing and masking? shadow u Blinn shadow Masked Light derives this factor for symmetrical v-shaped groove facets. (See paper).

F: Fresnel Reflection u Fraction of light incident on a facet that is actually

F: Fresnel Reflection u Fraction of light incident on a facet that is actually reflected rather than absorbed. u Function of angle of incidence and index of refraction. § § § F( , ). For metals (large ), F( , ) nearly constant at 1. For non-metals (small ), F( , ) has

Shading u Have seen some methods for computing lighting. § § Given normal, light

Shading u Have seen some methods for computing lighting. § § Given normal, light direction, material properties. Non-diffuse models need view direction. u Now explore methods of applying that lighting (or other color) to pixels of rasterized surface.

Types of Shading u In polygonal rendering, there are 3 main types: § §

Types of Shading u In polygonal rendering, there are 3 main types: § § § Flat shading. Gouraud shading. Phong shading. u These § § § roughly correspond to: Per-polygon shading. Per-vertex shading. Per-pixel shading.

Flat Shading u Fast and simple. u Compute the color of a polygon. u

Flat Shading u Fast and simple. u Compute the color of a polygon. u Use that color on every pixel of the polygon.

Gouraud Shading u Still pretty fast and simple. u Gives better sense of form

Gouraud Shading u Still pretty fast and simple. u Gives better sense of form than flat shading for many applications. u Basic Idea: § § Compute color at each vertex. Bi-linearly interpolate color for each interior pixel.

Gouraud Shading u Compute § SA, SB, SC for triangle ABC. Si = shade

Gouraud Shading u Compute § SA, SB, SC for triangle ABC. Si = shade of point i. u For a scanline XY, compute SX, SY by B lerping. § § e. g. t. AB = |AX| / |AB|. SA = t. AB* SA + (1 -t. AB)*SB u Compute § SP X A By lerping between SX and SY. P SX Y SP scanline SY C

Linear Interpolation Concerns u Perspective projection complicates linear interpolation. § § § Relationship between

Linear Interpolation Concerns u Perspective projection complicates linear interpolation. § § § Relationship between screen space distance and eye space distance is nonlinear. Therefore, relationship between interpolation in the two spaces is also nonlinear. Thus, screen space linear interpolation of colors (and texture coordinates) results in incorrect values. u Note: potential homework / test problem!

Perspectively-correct Interpolation u Could interpolate in eye space, then project every interpolated point. §

Perspectively-correct Interpolation u Could interpolate in eye space, then project every interpolated point. § Way too much work! u Can we interpolate in screen space and correct for perspective nonlinearity? § Yes!

Perspectively-correct Interpolation u For l a detailed derivation, see: http: //www. cs. unc. edu/~hoff/techrep/pers

Perspectively-correct Interpolation u For l a detailed derivation, see: http: //www. cs. unc. edu/~hoff/techrep/pers p. html u Here, § we skip to the punch line: Given two eye space points, E 1 and E 2. Can lerp in eye space: E(T) = E 1(1 -T) + E 2(T). l T is eye space parameter, t is screen space parameter. l § To see relationship, express in terms of screen space t: l E(t)= [ (E 1/Z 1)*(1 -t) + (E 2/Z 2)*t ] / [ (1/Z 1)*(1 -t) +

Perspectively-correct Interpolation u E(t)= [ (E 1/Z 1)*(1 -t) + (E 2/Z 2)*t ]

Perspectively-correct Interpolation u E(t)= [ (E 1/Z 1)*(1 -t) + (E 2/Z 2)*t ] / [ (1/Z 1)*(1 -t) + (1/Z 2)*t ] § § E 1/Z 1, E 2/Z 2 are projected points. Because Z 1, Z 2 are depths corresponding to E 1, E 2. u Looking closely, can see that interpolation along an eye space edge = interpolation along projected edge in screen space divided by the interpolation of 1/Z.

Gouraud Example

Gouraud Example

Mach Bands u Gouraud discusses “artifact” of lerping. u Mach bands: § § §

Mach Bands u Gouraud discusses “artifact” of lerping. u Mach bands: § § § Caused by interaction of neighboring retinal neurons. Acts as a sort of high-pass filter, accentuating discontinuities in first derivative. Linear interpolation causes first deriv. Discontinuities at polygon edges.

Mach Bands u Simple examples

Mach Bands u Simple examples

Improvements u Gouraud suggests higher-order interpolation would alleviate mach banding. § § But stresses

Improvements u Gouraud suggests higher-order interpolation would alleviate mach banding. § § But stresses the performance cost. Probably not worth it. u Phong shading helps the problem.

Phong Shading u Phong shading is not what earlier graphics hardware implemented. § APIs

Phong Shading u Phong shading is not what earlier graphics hardware implemented. § APIs (D 3 D, OGL) employ Blinn-Phong lighting and Gouraud shading. u Phong shading applies lighting computation per-pixel. § Uses linear interpolation of normal vectors, rather than colors.

Phong Shading u Interpolation just as with colors in Gouraud shading. § § §

Phong Shading u Interpolation just as with colors in Gouraud shading. § § § Interpolate scan line endpoint normals Na, Nb from endpoints of intercepted edges. Interpolate normal Np at each pixel from Na, N b. Normalize Np. l § (Interpolation of unit vectors does not preserve length). Back-transform Np to eye space, compute

Phong Shading u Results are much improved over Gouraud. § § Harder to tell

Phong Shading u Results are much improved over Gouraud. § § Harder to tell low- from high-polygon models. Still some indicators and problems: Silhouette still has a low tessellation. l Shared vs. Unshared vertices. l Mach banding. l • Yep, can still get first derivative discontinuities.

Other Types of Per-pixel Shading u Ray § § tracing. Doesn’t use Gouraud or

Other Types of Per-pixel Shading u Ray § § tracing. Doesn’t use Gouraud or Phong shading. Each pixel uses own ray to determine color. Can apply arbitrary lighting model. l Classical (Whitted) ray tracing uses Phong model. l § Since ray tracing determines colors based on intersections, don’t have to use polygonal geometry. l Thus, can potentially use exact normals, rather than interpolation.

Other Types of Per-pixel Shading. u New hardware provides per-pixel capabilities. § § §

Other Types of Per-pixel Shading. u New hardware provides per-pixel capabilities. § § § E. G. NVIDIA pixel shaders. Allow (somewhat) arbitrary programs on each pixel. So new hardware can implement Phong shading. u Also, § vertex programs. Allow (somewhat) arbitrary programs on each vertex.

References u Gouraud, Phong, Blinn papers I handed out. § Available in Seminal Graphics,

References u Gouraud, Phong, Blinn papers I handed out. § Available in Seminal Graphics, ACM press. u Glassner, Principles of Digital Image Synthesis, volume two. § Highly detailed and low level. u Möller and Haines, Real-Time Rendering. § A great book, with the best bibliography

References u Rogers, Procedural Elements for Computer Graphics. § One of my favorites. u

References u Rogers, Procedural Elements for Computer Graphics. § One of my favorites. u Foley, van dam, et al. Computer Graphics, Principles and Practice. § Not the best treatment, but it covers everything.