# Question about tangleL in HLSL

This topic is 2077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I followed luna frank's book and there is a chapter about character animation.

And the tangent in the model file has 4 parameters,x,y,z,w

like this:

Position: -29.23707 36.87918 6.136633
Tangent: 0.6117516 -0.2277735 0.757548 -1(what does the -1 mean? How to get it?)
Normal: -0.7813078 -0.3238094 0.5335782
Tex-Coords: 0.1640153 0.9827246
BlendWeights: 0.4420666 0.4420666 0.09699529 0.01887145
BlendIndices: 45 46 43 44

I am very confused,what does the forth parameter mean?

There are some HLSL code from the book

VertexOut SkinnedVS(SkinnedVertexIn vin)
{
VertexOut vout;

// Init array or else we get strange warnings about SV_POSITION.
float weights[4] = {0.0f, 0.0f, 0.0f, 0.0f};
weights[0] = vin.Weights.x;
weights[1] = vin.Weights.y;
weights[2] = vin.Weights.z;
weights[3] = 1.0f - weights[0] - weights[1] - weights[2];

float3 posL     = float3(0.0f, 0.0f, 0.0f);
float3 normalL  = float3(0.0f, 0.0f, 0.0f);
float3 tangentL = float3(0.0f, 0.0f, 0.0f);
for(int i = 0; i < 4; ++i)
{
// Assume no nonuniform scaling when transforming normals, so
// that we do not have to use the inverse-transpose.

posL     += weights[i]*mul(float4(vin.PosL, 1.0f), gBoneTransforms[vin.BoneIndices[i]]).xyz;
normalL  += weights[i]*mul(vin.NormalL,  (float3x3)gBoneTransforms[vin.BoneIndices[i]]);
tangentL += weights[i]*mul(vin.TangentL.xyz, (float3x3)gBoneTransforms[vin.BoneIndices[i]]);
}

// Transform to world space space.
vout.PosW     = mul(float4(posL, 1.0f), gWorld).xyz;
vout.NormalW  = mul(normalL, (float3x3)gWorldInvTranspose);
vout.TangentW = float4(mul(tangentL, (float3x3)gWorld), vin.TangentL.w);

// Transform to homogeneous clip space.
vout.PosH = mul(float4(posL, 1.0f), gWorldViewProj);

// Output vertex attributes for interpolation across triangle.
vout.Tex = mul(float4(vin.Tex, 0.0f, 1.0f), gTexTransform).xy;

// Generate projective tex-coords to project shadow map onto scene.

// Generate projective tex-coords to project SSAO map onto scene.
vout.SsaoPosH = mul(float4(posL, 1.0f), gWorldViewProjTex);

return vout;
}


Any help would be appreciated!Thanks!

##### Share on other sites

It probably indicates the winding order (clockwise, counter-clockwise) of the triangles in UV space. Is it used to invert one of the axes of the tangent space matrix in the accompanying pixel shader?

##### Share on other sites

It probably indicates the winding order (clockwise, counter-clockwise) of the triangles in UV space. Is it used to invert one of the axes of the tangent space matrix in the accompanying pixel shader?

Thanks for your reply!But how should I known if it's clockwise or counter-clockwise?This really confused me

##### Share on other sites

Say you have a triangle with vertex-UVs: uv0, uv1 and uv2; the direction of the normal (its z-component) of the triangle determines the winding order:

normal = normalize(cross(uv1 - uv0, uv2 - uv0))

tangent.w = normal.z

The cross-product can be simplified since the z-components of the uvs are always zero:

tangent.w = sign((uv1.x - uv0.x) * (uv2.y - uv0.y) - (uv1.y - uv0.y) * (uv2.x - uv0.x)));
Edited by eppo

##### Share on other sites

Say you have a triangle with vertex-UVs: uv0, uv1 and uv2; the direction of the normal (its z-component) of the triangle determines the winding order:

normal = normalize(cross(uv1 - uv0, uv2 - uv0))

tangent.w = normal.z

The cross-product can be simplified since the z-components of the uvs are always zero:

tangent.w = sign((uv1.x - uv0.x) * (uv2.y - uv0.y) - (uv1.y - uv0.y) * (uv2.x - uv0.x)));

Got it,thank you very much

• 21
• 12
• 9
• 17
• 13