Tangent space:
Because the video card is generally used as the smallest rendering unit, we assume that the three points of the triangle are P1, P2, and P3, and set the space corresponding to the triangle to (T, B, n ), where T and B constitute the plane where the triangle is located, and T and B correspond to the u and v directions respectively.
The function is to convert any vector from the tangent space to the world space (in fact, what we ultimately need is the reverse, so we can describe it first, and finally find the inverse)
Then the vector p of P2-P1 must be in the plane of T and B, which is introduced as follows:
P2-P1 = (U2-U1) * t + (V2-V1) * B
P3-P1 = (U3-U1) * t + (V3-V1) * B
V1 = P2-P1; v2 = P3-P1; S1 = U2-U1; S2 = U3-U1; T1 = V2-V1; t2 = V3-V1
The following matrix is obtained:
| V1 | S1 T1 | T |
| = | * |
| V2 | S2 T2 | B |
V1 V2 S1 S2 T1 T2 are known, so that T and B can be obtained, and N can be obtained using the cross multiplication of T and B.
Finally, we need T, B, and N to convert the vectors from World Space to tangent space. We only need to reverse the vectors.
Well, with this, we can change the light to the tangent space and then multiply the normal line in the noraml diagram when processing the normal map.