Normal texture Principle

Source: Internet
Author: User
Tags modulus

Normal texture Principle]

If the normal is in the world space, it is called World Space normal. If the object is in the local coordinate of the object itself, it is called the object space normal.

It is easy to imagine that once the World Space normal is extracted from the texture, it can be used directly, with high efficiency. However, this world space normal is fixed,If the object does not maintain its original direction and position, the original normal map will be voided..

So another person saves the object space normal. It is extracted from the texture. It also needs to be multiplied by the Model-View matrix to convert to the world coordinates, or the conversion to other coordinates depends on the computing process and needs. The texture generated by the object space normal. The object can be rotated and displaced, which is basically satisfactory. But there is still a disadvantage. YesA texture can only correspond to a specific model, and the model cannot be deform).

During deformation, the vertex relationship changes, that is, the shape of the surface, and the direction changes. If there is a fixed Coordinate System on the plane, when the object is deformed, moved, or rotated, the coordinate system must move along with the plane, then a point or vector in the coordinate system, no change is required. When the whole area changes, weYou only need to calculate the transformation matrix from the coordinate system on the plane to the world coordinate system. Then, the point or coordinate defined on the plane (fixed) is multiplied by the matrix to obtain the coordinates in the world.This coordinate system is called tangent space.

  According to the new method, each plane has a local coordinate system,When the low modulus is changed, that is, when the triangle surface changes, its tangent space also changes, multiply the normal value stored in the texture by the tangent space of the lower modulus to the conversion matrix of the external coordinate system to obtain the external coordinates.

In CG, the vertex has the tangent and normal information, and txn can get B. T, B, and N can be used to construct the switching space.

Now we can analyze why the tangent space normal map is blue. during surface rendering, the computer considers this surface to be "Curved" to a very small extent, that is, the deviation between the normal obtained by interpolation of each point on the surface is very small. the vertical direction is not much different from the whole. therefore, in the tangent space, these rectangles are less deviated from the Z axis. the Z axis is saved in the B-byte (blue channel) of the texture. so the color displayed by the texture is blue.

Suppose we have calculated the TBN matrix for a certain surface on the low mode, and obtained the normal value corresponding to a point on the surface in the normal map. now we need to calculate the illumination. we can convert the light vector to the tangent space for calculation. you can also convert the obtained normal vector to the World Space and the light vector for computation. the results are the same. in practice, you will find that the latter method is not good. for each vertex on the plane, a conversion from normal to World Space is calculated. the previous method, for all vertices on a surface, only one calculation of the light vector to the tangent space is required. then, considering the vertex shader and fragment shader processes, you will find that we can calculate the light-to-tangent space conversion in vertex shader, in fragment Sader, retrieve the normal value and calculate the light direction in the preceding tangent space. here, we will remind you that the light direction we get in verteix shader is generally based on world space, while the normal texture stores the direction in the high-mode object space and then converts it to tangent space, therefore, in vertex shader, we must first convert the light to the object space and then to the tangent space. in this way, the light and the normal are based on the same coordinate system. this is why you have seen functions like toojectspacedir (lightdir) in many normal map shader. It is precisely because you want to convert light to object space.

Reference: http://blog.csdn.net/damenhanter/article/details/22481563

Normal texture Principle

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.