 # Chapter IX Bump Mapping

## Presentation on theme: "Chapter IX Bump Mapping"— Presentation transcript:

Chapter IX Bump Mapping

Bumpy Surfaces Image texturing only Highly tessellated mesh
Fast Not realistic Highly tessellated mesh Realistic Slow A way out of this dilemma Use a smooth coarse mesh called macrostructure. Store the high-frequency geometric details in a texture. Use the texture at run time. This technique is generally called bump mapping.

Height Field A popular method to represent a high-frequency surface is to use a height field. It is a function h(x,y) that returns a height or z value given (x,y) coordinates. The height field is sampled with a 2D array of regularly spaced (x,y) coordinates, and the height values are stored in a texture named height map. The height map can be drawn in gray scales. If the height is in the range of [0,255], the lowest height 0 is colored in black, and the highest 255 is colored in white.

Height Field for Bump Mapping
Bump mapping was originally proposed by J. Blinn in 1978. Each surface point of the macrostructure is to be displaced in the direction of its surface normal. The displacement amount is fetched using (u,v) from the height map.

Height Field for Bump Mapping (cont’d)
Three algorithms – How to handle the height map Normal mapping The oldest but the most popular It pre-computes a special texture, normal map, from the height map. At run tome, the normal map is used to perturb the surface normals of the macrostructure so as to ‘mimic’ the geometric bumpiness. Implemented in fragment shader Parallax mapping It takes the height map at input, and runs a simplified ray tracing algorithm. Unlike normal mapping, it makes the bumps appear to block each other. Displacement mapping It tessellates the macrostructure and then displaces its vertices using the height map. It is emerging as an attractive algorithm due to the tessellation support in Shader Model 5. Implemented in the domain shader with the aid of tessellator.

Normal Mapping Recall the interaction among light sources, surfaces, and camera/eye. Why light and why dark? Surface normals play key roles in lighting.

Normal Mapping (cont’d)
Use a macrostructure. Store the surface normals of the high-frequency surface into a texture, called the normal map. At run time, use the normal map for lighting.

Normal Map Simple image-editing operations can create a gray-scale image (height map) from an image texture (from (a) to (b)). The next step from (b) to (c) is done automatically.

Normal Map (cont’d) Creation of a normal map from a height map
Visualization of a normal map

Normal Mapping The height field (height map) could be handled by the fragment shader. The macrostructure is rasterized. When the fragment shader processes p, the point actually visible to the viewpoint should be (u',v',h(u',v')). The visible point could be computed using ray tracing. Then, both the normal map and the image texture are filtered using (u',v'). Ray tracing is (‘was’) not easy to implement. Assume that, compared to the extent of the macrostructure, the height values of the height field are negligibly small. Then, the visible point is approximated to be p, and p's texture coordinates (u,v) can be used to access the textures. Then, we may not need the height map but simply use the normal map.

Normal Mapping (cont’d)
The normal at (u,v) is obtained by filtering the normal map through bilinear interpolation. Recall the diffuse reflection term max(n•l,0)sdmd. The normal n is fetched from the normal map. md is fetched from the image texture.

Normal Mapping (cont’d)

Normal Mapping (cont’d)

Normal Mapping (cont’d)

Tangent-space Normal Mapping
So far, it has been implicitly assumed that the normal map stores the perturbed instances of uz, which represents the world-space z-axis. It’s not good. Recall that texturing is described as wrapping a texture onto an object surface. Note that n(up,vp) will replace np, and n(uq,vq) will replace nq. So, the normals of the normal map should be considered as perturbed instances of the surface normals, not of uz.

Tangent-space Normal Mapping (cont’d)
For a surface point, consider a tangent space, the z-axis of which corresponds to the surface normal. Assuming that a tangent space is defined for a surface point to be normal-mapped, the normal fetched from the normal map is taken as defined in the tangent space of the point, not in the world space. In this respect, the normal is named the tangent-space normal.

Tangent-space Normal Mapping (cont’d)
The basis of the tangent space {T,B,N} Vertex normal N – defined per vertex at the modeling stage. Tangent T – needs to compute Binormal B – needs to compute Utility functions such as D3DXComputeTangentFrameEx return the TBN vectors on each vertex of a triangle mesh. With the tangent space, we can take the normal from the normal map as is.

Tangent-space Normal Mapping (cont’d)
The diffuse term of the Phong lighting model A light source is defined in the world space, and so is l. In contrast, n fetched from the normal map is defined in the tangent space. To resolve this inconsistency, l has to be redefined in the tangent space. Typically, the per-vertex TBN-basis is pre-computed, is stored in the vertex buffer, and is passed to the vertex shader. Then, the vertex shader constructs a matrix that rotates the world-space light vector into the per-vertex tangent space.

Tangent-space Normal Mapping (cont’d)

Tangent-space Normal Mapping (cont’d)
The the tangent-space light vector l and the texture coordinates (u,v) for referencing the normal map are passed to the rasterizer. They are interpolated. The fragment shader computes lighting using the interpolated light vector (l) and the normal (n) retrieved from the normal map.

Tangent-space Normal Mapping (cont’d)

Computing Tangent-space
Why is it crucial to correctly compute T and B?

Computing Tangent-space (cont’d)
Note that x-, y-, and z-axes of the normal map space correspond to T-, B-, and N-axes of the tangent space, respectively. Also note that the texture axis u is identical to the T-axis. Similarly, the v-axis is identical to the B-axis. Therefore, analyzing the texture coordinates (ui,vi)s assigned to the vertices, we can determine the directions of the T- and B-axes. Ti and Bi are computed for every triangle i sharing p0. All Tis and Bis are summed to define T' and B', respectively. Finally, the Gram-Schmidt algorithm is invoked to convert {T’,B',N} into an orthonormal basis.

Similar presentations