CSC418 - Notes
Topic 8: Texture Mapping
Navigation: back up
next notes exercises
Key concepts & Readings
- Texture mapping (Shirley: c. 10. Hill: p. 439-465. Foley & van Dam: p. 741-744)
- 2d texture mapping (Shirley: p. 198-199)
- 3d texture mapping or volumetric textures (Shirley: p. 192-198)
- Bump textures (Shirley: p. 204)
- Environment maps (Shirley: p. 205-206)
OpenGL
OpenGL has built-in support for 1D and 2D texture mapping.
2D Texture Mapping
- Enable texture mapping by calling
glEnable(GL_TEXTURE_2D)
- Load a texture (either generate a texture on the fly or load one from an image)
- Setup OpenGL to use the texture by calling
void glTexImage2D(GLenum target, GLint level, GLint components, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
Example:
glTexImage2D(GL_TEXTURE_2D, 0, 3, textureImageWidth, textureImage, 0, GL_RGB, GL_UNSIGNED_BYTE, &textureImage[0][0][0]);
- Setup wrapping and filtering options of the texture
void glTexParameterf(GLenum target, GLenum pname, GLfloat param)
void glTexParameteri(GLenum target, GLenum pname, GLint param)
- In the display function
- Setup the texture coordinates by calling
glTexCoord*()
- Draw the scene
Notes
Texture Mapping
efficient way to add surface detail
- pastes an elastic photograph onto a surface
- used to modify colour, normals, ...
- requires prefiltering
Coordinate Systems
Shape of Filter Kernel
Fast Convolution for Texture Maps
- usually box filter
- quickly sum texels within filter kernel (preferably constant time)
- summed-area tables
- MIP maps
Bump Mapping
Bump Mapping: The surfaces appear to have bumps or gouges but that the silhouette of the object is still smooth.
(Courtesy www.siggraph.org.)
- creates impression of small surface features
- wrinkles, dimples, etc. -- orange peel
- perturbs surface normal, affecting local illumination
- silhouette edges don't have bumps, no shadows from bumps
Volumetric Textures OR 3D Textures
- wood, marble
- colour = f(x,y,z)
Environment Mapping
to be written
Exercises