Upload
hoangdien
View
217
Download
3
Embed Size (px)
Citation preview
Picking colors
• Shading is finding the right color for a pixel
• This color depends on several factors:
• The material of the surface itself
• The color and angle of incoming light
• The angle of outgoing light to the eye
• There are several “types” of shading
Diffuse reflection
• Incoming light is reflected in all directions
• Completely uniform reflection is called Lambertian
• Pattern of light and dark does not change with viewing angle, only the locations of object and light[WP]
Specular reflection
• Light that is reflected (mostly) coherently
• View dependent: the reflection you see depends on where you, the object, and the light are
[WP]
Diffuse and specular
• There’s a continuum of sorts between the two
• You can have both effects at once as well [RTR]
The rendering equation
• Computer graphics didn’t really know what it was doing with shading until 1986
• Tons of models had been proposed, that looked good in different circumstances
• Jim Kajiya came along with the rendering equation, which formalized what the heck we were trying to do
Definitions
• x is the point at which we’re evaluating shading
• ω is the normalized outgoing light direction (to eye)
• λ is the wavelength of the light
• t is the time
• n is the surface normal at x
• Lo is the outgoing light from x to the eye
• Le is emitted light from the surface, going to the eye
Inside the integral
• Ω is the hemisphere centered around n at x
• This means the integral is over all incoming light directions
• ω′ is one particular normalized incoming light direction
• Li is the incoming light along ω′
• (-ω′ • n) is the cosine of the angle between the normal and the incoming light direction
Cosine weighting
• At sharper angles, incoming light is spread out over a wider area, and thus gets dimmer
• Hence the cosine weighting term
cos(0°) = 1 cos(45°) ≈ .71 cos(70°) ≈ .34
BRDF
• fr is called the BRDF: Bidirectional Reflectance Distribution Function
• Captures how much light is reflected by every surface point at every incoming and outgoing angle, at every wavelength and time
• Always positive (there no negative light)
• Bidirectional: fr(x , ω′, ω, ...) = fr(x , ω, ω′, ...)
• Incredibly general, most BRDFs have much simpler form
Rendering equation
• This is the gold standard: perfect rendering
• But evaluating it is impossibly expensive
• Especially considering light bouncing around
• Every shading model we make in graphics is an approximation to the rendering equation
• This version is only for opaque surfaces, there are other versions for transparent ones
Local shading
• Make some simplifying assumptions to make the rendering equation more tractable
• When evaluating a point’s shading, ignore everything except the eye, the surface, and the light(s)
• No multiple bounces, shadows, refractions, etc.
• Lights are just points in space (no area)
• We’ll use this to build a very simple approximation of the real thing
Some terminology
• v is a normalized vector to eye, l is same to light, n is the surface normal, p is the point on the surface
• L is incoming light, k are constants between 0 and 1, and I is outgoing light (one set for each RGB)
[RTR]
Approximation 1: ambient
• Every point on the object is a constant color
• Completely ignore all angles and surface geometry[WP]
Approx. 2: diffuse
• Add in the cosine weighting term from the rendering equation, gives a Lambertian surface
• Smooth changes in brightness if n changes smoothly, does not depend on v
• Clamp dot product to [0, 1]! [WP]
Approx. 3: specular
• We’d like to add some specular reflection
• Highlights shift around with both light and viewer
• Perfect specular isn’t interesting for point lights; we’d like to widen the reflections a bit [WP]
Blinn-Phong specular
• This is a simpler specular approximation
• Uses the halfway vector h = norm(v + l)
• α is the specular exponent or shininess parameter
• Again, clamp dot product to [0, 1]! [RTR]
Shininess exponent
• Lower exponents make a wider highlight, higher ones make a sharper highlight
[RTR]
Adding it all together
• Combine the ambient, diffuse, and specular approximations to get a decent local lighting model
• 3 of these equations: one for each R, G, and B[WP]
Blinn-phong lighting
• If you have multiple lights, just sum them up
• This local lighting model has pretty much been the standard for real-time graphics for the last 20 years
• The default lighting model in OpenGL
• Tends to make everything look like plastic
• Much better local models exist for certain types of renderings, but it’s still the most common by far
Light types
• We’ve assumed point lights so far, but there’s more stuff you can add for different behavior
Directional lights
• Treated like point lights placed an infinite distance away
• Light rays are always parallel, l never changes
[RTR]
Light attenuation
• If a light emits a certain amount of energy, then the energy received on a surface should fall off as 1/r2, where r is distance from the light
[RTR]
Light attenuation
• The quadratic falloff law tends to look unnaturally dark on its own, so we represent it instead as the reciprocal of a general quadratic function
• This allows us to give it a softer falloff
• Just multiply the light parameters by the falloff
Spotlight
• You can also define a spotlight, which is like a cross between direction and point lights
• They point in a direction, but fall off as a function of both distance and angle from their direction
• d is the direction the spotlight points, p is the sharpness of the beam (works like shininess)
• Again, must clamp dot product to [0, 1]
Applying thelighting model
• Evaluating a shading model is generally expensive
• We can occasionally get away with evaluating it sparsely and reusing the results somehow
Flat shading
• Evaluate your lighting model at the center of each face, then fill the entire face with that color
• Gives a sparkly or gemstone like appearance[RTR]
Gouraud shading
• Evaluate lighting just at vertices, then interpolate those colors across the faces of each triangle
• Gives a much smoother appearance, but is dependent on resolution of mesh
[RTR]
Mesh resolution
• Gouraud can miss detail at low resolution
• Leads to popping when meshes are moved around [RTR]
Phong shading
• Interpolate vertex normals along triangles, then use those normals to evaluate per-pixel lighting model
• Most expensive, but has best results
[RTR]
Interpolating normals
• Linear interpolation will cause non-unit-length normals to be generated
• You must renormalize your interpolated normals before using them in the lighting calculation
[RTR]
figures courtesy...
• Real-Time Rendering, 3rd ed. [RTR]
• Tomas Akenine-Moller, Eric Haines, Naty Hoffman
• Mathematics for 3D Game Programming and Computer Graphics, 3rd ed. [M3D]
• Eric Lengyel
• Interactive Computer Graphics: A Top-Down Approach Featuring Shader-Based OpenGL, 6th ed. [ICG]
• Edward Angel, Dave Shreiner
• Wikipedia [WP]