CSCE 441 Lecture 19

From Notes
Jump to navigation Jump to search

« previous | Wednesday, February 26, 2014 | next »


Midterm on Monday

Texture Mapping: Other Uses

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

Environment Mapping

Cheap attempt at modeling reflections

Make surfaces look metallic

  • Use six textures to model faces of a cube
  • Store color of reflection on each face
  • assume faces are infinitely far away (only need direction to determine color of texture)
  • Textures are typically static
  • Doesn't take into account occlusion (objects in the way of reflected texture

Bump/Normal Mapping

Replace colors with X,Y,Z coordinates, and interpret pixels as normal vectors.

Can make a low-resolution surface look more complicated than it actually is


Displacement Mapping

Offset geometry in direction of normal

Encode offset (extrusion distance) inside texture

Actually changes geometry

Can be difficult or expensive to render in real-time


Problems with Texture Mapping

Boundary mapping
Along the boundary, texture mapping will sample from outside the texture range.
Discontinuity between different chart pieces (huge problem for displacement mapping)
Edge Scaling
the edge lengths in different charts can be scaled differently, so the point where they meet can
Display scaling
If projected model on display is small, what if the pixel on display maps to an "island" in the texture?
Pixel on model actually maps to a region on the texture (box filtering; bad for signal processing, but better than point sampling)
Value of scaled display model should be average of texuter


Mipmapping

Compute scale textures of the original texture

Pick two closest images based on size of sampling region

Perform bilinear sample between images

Compute average between each sample

This is called trilinear filtering

Magnifies boundary problems


OpenGL and Shading

// glShade  // unfinished...

unsigned int texID, imageW, imageH;
unsigned char *image = loadImage("puppy.jpg", &imageW, &imageH);  // Bring your own library.

glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // nearest neighbor sampling when 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  // bilinear sampling

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imageW, imageH, 0, GL_RGB, GL_UNSIGNED_BYTE, image);


// render the texture
glBindTexture(GL_TEXTURE_2d, texID);
glBegin(GL_TRIANGLES);
    //...
    glTexCoord2f(u,v);
    glVertex3f(x,y,z);
    //...
glEnd();



Hidden Surfaces

Many polygons of a model could map to the same pixel.


Backface Culling

improves rendering speed by removing roughly half of polygons from scan conversion, but assumse closed surface with consistently oriented polygons

(not a true hidden surface removal algorithm since correctly oriented polygons can still overlap, but commonly used)

If , then draw the polygon, otherwise, if , then cull (throw away) polygon

  • is the polygon normal
  • is the viewer vector


Orientation

If polygon is facing toward the user (counter-clock-wise orientation of vertices), then draw it.

If polygon is facing away from the user (clock-wise orientation of vertices), then throw it away.


Painter's Algorithm

Sort polygons according to distance from viewer

Draw from back to front

How do we sort polygons?