110 likes | 141 Views
Module 05. Advanced mapping techniques: Bump mapping. Overview. Multitexturing Texture units Bump mapping. Multitexturing. When you map a texture to polygon, you apply only one texture to it.
E N D
Module 05 Advanced mapping techniques: Bump mapping
Overview • Multitexturing • Texture units • Bump mapping
Multitexturing • When you map a texture to polygon, you apply only one texture to it. • It's actually possible to apply several textures to the same polygon through a series of texture operations. This is called multitexturing. • Multiple textured objects rendered in a single pass: • Lightmaps • Fog • Bump mapping • Multitexturing makes use of a series of texture units. Each texture unit represents a single texture application, and when you perform multitexturing, each texture unit passes its results to the next texture unit.
Texture units (1) • Each texture unit has a set of states associated with it that allows it to keep settings separate from the other texture units. Each texture unit has its own texture environment, texture matrix stack, texture coordinate generation states, and texture image and filtering parameters. • The latter texture units are usually derived from the texture object that is bound to the texture unit • In addition, each of the texture targets (GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D and GL_TEXTURE_CUBE_MAP) are enabled or disabled on a per-texture-unit basis.
Texture units (2) • Default texture unit is texture unit 0. • Texture unit pipeline:
Texture units (4) Code Example: Texture1 and texture2 are handles to valid texture objects for 2D textures. The following code binds them to texture unit 0 and texture unit 1: glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D): glBindTexture(GL_TEXTURE_2D, texture1); glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture2);
Bump mapping (1) • Bump mapping is a technique that presents the illusion of greater detail to the viewer by using a texture map to perturb the normal vector at each pixel. • High-resolution information about how the normal vector is perturbed is stored in a two-dimensional array of three-dimensional vectors called a bump map or normal map. • Each vector in the bump map represents the direction in which the normal vector should point relative to the interpolated normal vector at a point inside the face of a triangle. • A bump map is typically constructed by extracting normal vectors from a height map whose contents represent the height of a flat surface at each pixel.
Bump mapping (2) • To derive the normal vector corresponding to a particular pixel in the height map, we first calculate tangents in the s and t directions, which are based on the difference in height between adjacent pixels. • Corresponding normal vector N(i,j) is: • This process is computationally very expensive in real time
Bump mapping (3) • To achieve quite the same result as lighting calculation at each pixel based on perturbed normal vectors, we can use OpenGL multitexturing, diffuse lighting and picture emboss effect, provided by image editor like Adobe Photoshop. • Example: + = Default texture Embossed texture Bump-mapped texture
Practice Open: Lab05 / BumpMapping / BumpMapping.sln