Justin Zhang

JustinZhang

About Me

Connect

LOCATION
Not Specified
ウェブサイト

Houdini Skills

Availability

Not Specified

Recent Forum Posts

How to recreate the original vector from tangent space ? 2023年2月16日4:44

Currently, there is a need to convert normals from model space to tangent space in Houdini, and save them to vertex color. Then in Unity Shader, the normals can be converted from tangent space to model space by reading vertex color.
vector T = normalize(v@tangentu);
vector B = normalize(v@tangentv) ;
vector N = normalize(@N);
matrix m = set(@T, @B, @N);
@Cd = m * @Cd;
@Cd = @Cd * {-0.50.50.5} + 0.5;  //unity is leftHand
In Unity Shader:
float3 bitangent = cross(normalize(v.normal) , normalize(v.tangent.xyz)) * v.tangent.w;
float3x3 TtoO = float3x3(v.tangent.x, bitangent.x, v.normal.x,
            v.tangent.y, bitangent.y, v.normal.y,
            v.tangent.z, bitangent.z, v.normal.z);
float3 normalOS = v.color.xyz;
normalOS = normalOS * 2 -1;
normalOS = mul(TtoO, normalOS) ;
But the normals generated by this method are incorrect. We conducted the following test: In Houdini, we directly wrote the normals into the vertex color channel.
@Cd = @N;
@Cd = @Cd * 0.5 + 0.5;
@Cd = normalize(@Cd);
@N = @Cd;

In RenderDoc:

When we wrote the same values to the normals and vertices, but in Unity, the vector order was different and the values had some deviations, including decimal points.

Can someone who has access to the Unity source code check what calculations Unity performs when importing FBX files, and how to construct the TBN inverse matrix in Houdini to restore the tangent space vectors written in Houdini?