# CS488 - Introduction to Computer Graphics - Lecture 20

## Review

1. Body reflection
2. Surface reflection

Terminology

• Add lighting effects that convey shape
• Masaccio
• Shape from shading'
• interpolate within polygons to eliminate faceting
• function applied at a pixel to determine colour once geometry and illumination are known

Meta-terminology

1. What an umbrella does to a person from the rain or the sun

We are doing Utah-graphics

• 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

Calculate at vertices and interpolate linearly

• derivative discontinuities at polygon edges
• Mach bands

Interpolating within triangles

1. 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
2. For practical interpolation we care about P -> P + v
• a1 -> a1 + (V3 - V2) x v / area of entire triangle
3. C(P) = a1 * C(V1) + ...
• C(P) is the determinant of a matrix, if you care
4. The calculations are affine-invariant, so you could
• transform a triangle into a standard triangle with an affine transformation
• 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.

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
colour the pixel with the result`

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