CSCE 441 Lecture 18

From Notes
Jump to navigation Jump to search

« previous | Monday, February 24, 2014 | next »


Shading / Texturing

Algorithms

Flat shading

Apply same color across entire polygon

  • calculate color once per polygon
  • center is typically used.

Not very expensive computation

Gouraud Shading

  • calculate normals at vertices of polygon
    • average the normals of the surrounding polygons
    • weight averages with area of function
  • If all normals are the same, then the result is same as flat shading
  • Determine color at each vertex and interpolate across polygon.

Good for diffuse lighting

Moderately expensive computation

Phong Shading

  • Assume normals at vertices of polygon
  • Interpolate normals from vertices across polygo n
  • Determine color at each pixel in polygon

Lot more expensive computation


Interpolating Over Polygons

Given numeric values at vertices of polygon, how do we interpolate data over the interior?


Augment scan conversion algorithm from before:

New Edge data structure:

  • maxY = max(y[i], y[i+1])
  • currentX = y[i] == min(y[i] + y[i+1]) ? x[i] : x[i+1]
  • xIncr = (x[i+1]-x[i]) / (y[i+1] - y[i])
  • currentF = y[i] == min(y[i] + y[i+1]) ? f[i] : f[i+1]
  • fIncr = (f[i+1]-f[i]) / (y[i+1] - y[i])

When computing entries active edge list,

  • currentF += fIncr

When drawing pixels

  • calculate value dF = (currentF[i+1] - currentF[i]) / (x[i+1] - x[i]
  • F = currentF[i]
  • If x is not an integer, multiply F by (1 + (1-x))
  • Add dF to x for each step in pixels.


Interpolating Normals

Spherical Linear Interpolation (SLERP)

We want a parameterized normal equation between and such that gives the normal with angles and for .

Length of all vectors are the same (i.e. 1).

We want an equation of the form

Linear interpolation not correct over perspective projections

Equidistant objects appear closer together as they get farther away in the -direction.

To fix this, we need rational interpolation


Texture Mapping

  • Geometry and lighting don't provide sufficient visible detail
  • Map a 2D image onto 3D surface.
  • 2D image chopped into "charts" to minimize distortion

3D coordinates have corresponding and coordinates in image.

During polygon drawing, look up color from images and multiply by shading value.

  • Nearest neighboring pixel: blocky results
  • Linear blending (interpolate value of coordinate from surrounding pixels): smooth appearance
  • Can be much more complicated


Other Uses

  • Environment Mapping
  • Bump/Normal Mapping
  • Displacement Mapping
  • ...

Any attribute of surface position, normal, color, etc. can be placed in a texture.