CS488 - Introduction to Computer Graphics - Lecture 20
Comments and Questions
Review
- Body reflection
- Surface reflection
Shading
Terminology
- Artist: shading
- Add lighting effects that convey shape
- Masaccio
- Psychologist: shading
- Utah-graphics: shading
- interpolate within polygons to eliminate faceting
- Renderman: shader
- function applied at a pixel to determine colour once geometry and
illumination are known
- GPU: shaders
- vertex shader
- geometry shader
- pixel shader
Meta-terminology
- What an umbrella does to a person from the rain or the sun
We are doing Utah-graphics
Flat Shading
Shade entire polygon one colour
- Which colour?
- The one calculated from
- illumination
- normal
- view point
- surface properties
- For which pixel
- average colour of all pixels in polygon -- (What?!!?)
- some particular pixel
Gouraud Shading
Calculate at vertices and interpolate linearly
- derivative discontinuities at polygon edges
- Mach bands
Interpolating within triangles
- Barycentric coordinates
- Three vertices: V1, V2, V3
- Inside point: P = a1*V1 + a2*V2 + a3*V3, subject to a1 + a2 + a3 =
1
- ai = area of triangle opposite Vi / area of entire triangle
- a1 = (V3 - V2) x (P - V2) / area of entire triangle
- For practical interpolation we care about P -> P + v
- a1 -> a1 + (V3 - V2) x v / area of entire triangle
- C(P) = a1 * C(V1) + ...
- C(P) is the determinant of a matrix, if you care
- The calculations are affine-invariant, so you could
- transform a triangle into a standard triangle with an affine
transformation
- shade it
- transform it back
BUT, the calculations are NOT projection-invariant
- Why?
- Graphics hardware can adjust so that you can shade in display
space
Interpolating within arbitrary polygons is a bad idea
- Divide into triangles
- But if you must, the algorithm is similar to scan-converting an
arbitrary polygon.
Phong Shading
Interpolate the vertex normals, light vectors, and view vectors
- Do the lighting calculation at each pixel
Highlights are more precise
Ray Tracing
The idea is simple:
for each pixel
calculate the eye/pixel ray
project the ray into the scene
find the first intersection
apply illumination and shading calculations
colour the pixel with the result
Eye-pixel ray
E + t*(P - E)
Object in scene
Set of points {Q} satisfying
- f(Q) = 0
- This is the surface of an object. (How do you know?)
- Why don't we care about inside points?
Solve the equation
- f( E + t*(P - E) ) = 0
for t
- Most of the time there is no solution
The surface might be defined by an algorithm, then use a root-finding
method
Object is planar, e.g. a triangle
Equation of the plane is \sum_i ai*xi = b
Return to: