@ -26,13 +26,12 @@ float3 WorldSpaceToTangent(float3 vectorWS, float3 normalWS, float3 tangentWS, f
return float3(a,b,c);
return float3(a,b,c);
}
}
//! Utility function for vertex shaders to transform vertex tangent, bitangent, and normal vectors into world space based on MikkT conventions .
//! Utility function for vertex shaders to transform vertex tangent, bitangent, and normal vectors into world space.
void ConstructTBN(float3 vertexNormal, float4 vertexTangent, float3 vertexBitangent, float4x4 localToWorld, float3x3 localToWorldInverseTranspose, out float3 normalWS, out float3 tangentWS, out float3 bitangentWS)
void ConstructTBN(float3 vertexNormal, float4 vertexTangent, float3 vertexBitangent, float4x4 localToWorld, float3x3 localToWorldInverseTranspose, out float3 normalWS, out float3 tangentWS, out float3 bitangentWS)
{
{
normalWS = normalize(mul(localToWorldInverseTranspose, vertexNormal));
normalWS = normalize(mul(localToWorldInverseTranspose, vertexNormal));
tangentWS = normalize(mul(localToWorld, float4(vertexTangent.xyz, 0)).xyz);
tangentWS = normalize(mul(localToWorld, float4(vertexTangent.xyz, 0)).xyz);
float bitangentSign = -vertexTangent.w;
bitangentWS = normalize(mul(localToWorld, float4(vertexBitangent, 0)).xyz);
bitangentWS = normalize(mul(localToWorld, float4(vertexBitangent, 0)).xyz) * bitangentSign;
}
}
// ---------- Normal Calculation ----------
// ---------- Normal Calculation ----------