Preliminary Pallax Mapping Effect.

xiaoxiao2021-03-05  34

A few days ago, I saw a gold medal on the SHADERTECH website, called relief mapping, which contains Relief Texture Mapping and Steep Parallax Mapping, which is very good, so I started to achieve its effect, because Steep Parallax mapping requires PS3. 0 support, Relief texture mapping requires the two-fork tree search, which is relatively high for resources, so it is temporarily implemented, and it is very good to find the effect. It is better than Normal Mapping.

It is mainly necessary to calculate several components in the tangent space, and the three components of Normal, Tangent, Binormal, in general, the normal components are relatively easy, and the binormal component is obtained by Tangent and Normal. And the calculation of Tangent is relatively complex, the following is C code:

For (DWORD I = 0; i

{Int nOffset = 3 * i; int idxVertex0 = tri [nOffset]; int idxVertex1 = tri [nOffset 1]; int idxVertex2 = tri [nOffset 2]; D3DXVECTOR3 v0 = D3DXVECTOR3 (vertex [idxVertex0]); D3DXVECTOR3 v1 = D3DXVECTOR3 (Vertex [idxvertex1]); D3DXVector3 V2 = D3DXVECTOR3 (Vertex [iDxvertex2]);

D3DXVECTOR2 w0 = D3DXVECTOR2 (vertex [idxVertex0] .u, vertex [idxVertex0] .v); D3DXVECTOR2 w1 = D3DXVECTOR2 (vertex [idxVertex1] .u, vertex [idxVertex1] .v); D3DXVECTOR2 w2 = D3DXVECTOR2 (vertex [idxVertex2]. u, vertex [idxvertex2] .v); float x1 = v1.x - v0.x; float x2 = v2.x - v0.x; float y1 = v1.y - v0.y; float y2 = v2.y - v0.y; float z1 = v1.z - v0.z; float z2 = v2.z - v0.z; float s1 = w1.x - w0.x; float s2 = w2.x - w0.x; float t1 = w1.y - w0.y; float t2 = w2.y - w0.y; float r = 1.0F / (S1 * T2 - S2 * T1); D3DXVECTOR3 SDIR ((T2 * x1 - t1 * x2) * r (T2 * Y1 - T1 * Y2) * R); D3DXVECTOR3 TDIR ((S1 * X2 - S2 * x1) * R, (S1 * Y2 - S2 * Y1) * R, (S1 * Z2 - S2 * Z1) * R); TAN1 [IDXVERTEX0] = SDIR; TAN1 [IdxVertex1] = SDIR; TAN1 [IdxVertex2] = SDIR; Tan2 [IDXVERTEX0] = TDIR; TAN2 [ IDXVERTEX1] = TDIR; TAN2 [IDXVERTEX2] = TDIR;}

For (i = 0; i normal; d3dxvector3 & t = tan1 [i]; float a = nx * Tx NY * TY NZ * TZ; D3DXVEC3NORMALIZE (& VERTEX [I] -> TANGENT, & (T - N * a)); D3DXVECTOR3 TEMP; D3DXVEC3NORMALIZE (& VERTEX [I] -> Binormal, D3DXVEC3cross (& TEMP, & N, & VERTEX [I] -> tangent);}

This will get three components of Tangent and Binormal and Normal and Normal, then take these three components to three components of XYZ, get a new float3, and tell these three components to take VEYE XYZ. The three components gave a new FLOAT3, which is the purpose of converting the position of VEYE and VLIGHT to the tangent. Then the PS is again for high levels of colors, that is, the color is calculated.

转载请注明原文地址:https://www.9cbs.com/read-33222.html

New Post(0)