Shadersimpler (5): bump mapping (Normal mapping)

Source: Internet
Author: User

Source code: http://yanonsoftware.googlepages.com/ShaderSimpler.zip

Generate normal map from texture
Normal map must be generated from the height map corresponding to a color map. In order to calculate the I, J point's normal, we can first calculate the S, T direction Tangent Vector Based on the height difference:
S (I, j) = <1, 0, AH (I + 1, J)-Ah (I-1, j)>
T (I, j) = <0, 1, AH (I, j + 1)-Ah (I, J-1)>
A is a scaling factor. Normal can be obtained from the two tangent vectors.
N (I, j) = normalize (Cross (S, T) = cross (S, T)/length (Cross (S, T) = <-SZ, -tz, 1>/SQRT (SZ ^ 2 + TZ ^ 2 + 1)
You can then store this vector in the texture file using RGB encoding. In this example, we use a tool provided by NVIDIA to generate a normal map.

Calculate the tangent space
This computation is a little complicated. I remember that NVIDIA had clearly written a document earlier, but I couldn't find it. If anyone knows, please give me a link. I found another solution in Eric Lengyel's book, which is also very thorough.
In this example, d3dxcomputetangent is called. You can also use the nv_meshmender provided in the nvidia sdk for computation.

Illumination computing
The light Computing Using bump map is nothing new than the previous phongshading example. In the preceding example, the normal value of each pixel is simply interpolated from the vertex normal. After the bump map is used, the normal value of each vertex can be searched from the texture; in addition, because this normal operation exists in the tangent space, we need to convert both light Dir and view dir to tangent space for calculation.

Capture: http://yanonsoftware.googlepages.com/bumpMap.jpg

Reference
Eric Lengyel, mathematical methods in 3D games and computer graphics
Normal map maps are generated using NVIDIA Photoshop Plugin-http://developer.nvidia.com/object/nv_texture_tools.html
Wolfgang Engel, implementing lighting models with HLSL -- http://www.gamasutra.com/features/20030418/engel_01.shtml
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.