* Original articles, reproduced please indicate the source *
Open GL CG Series Tutorials 06–normal Mapping ( normal map )
Normal Mapping (normal mapping), whether in game development or other computer graphics development is a very wide range of technology. If the surface of an object is rough and uneven, the normal of the vertex of the object is heading in different directions, so the object looks uneven. To represent such an object, of course, you can use quite a few vertex data that contains different normals, and this is a very inefficient way to do so. This approach is clearly not applicable in interactive graphics programs that require high timeliness, such as games. In order to solve this problem, the concept of normal mapping is proposed.
Normal mapping is a normal texture map, but unlike a normal texture map, each pixel in the normal map holds the normal data. Normal maps are typically generated by a height map. Height diagram is a 8-bit grayscale, the darker the color represents the lower the height, the lighter the color represents the higher the height. As shown in Figure Fig1 (a) is a picture of the height generated by Photoshop. As you can see in Figure Fig1, a normal graph (b) is generated from the height diagram (a) and then affixed to the surface of the object (c), the lighter part represents the "convex" part of the object's surface, and the darker part of the height image represents the "concave" part of the object's surface
(a). Height map |
(b). Normal diagram |
(c). Applied to the surface of the object |
Fig1. Height diagram and normal diagram
Let's take a look at how to generate normal graphs from a height. Using the data in the height map, two difference vectors (1, 0, HR–HG) and (0, 1, HA–HG)are computed, and the normals are equal to their outer product. Where Hg is the current pixel,Ha is a pixel above the current pixel, andHr is the right pixel of the current pixel. The relationship between them can be clearly seen from the figure Fig2 below.