compressing normal space to qtangents

This commit is contained in:
Dynamitos
2024-12-31 12:10:26 +01:00
parent d3a2617d7f
commit 382e2d30f5
7 changed files with 80 additions and 84 deletions
+5 -8
View File
@@ -12,7 +12,6 @@ struct LightingParameter
float3x3 tangentToWorld;
float3 viewDir_WS;
float3 position_WS;
float3 normal_WS;
}
@@ -92,7 +91,6 @@ struct FragmentParameter
result.tangentToWorld = getTangentToWorld();
result.viewDir_WS = normalize(pViewParams.cameraPosition_WS.xyz - position_WS);
result.position_WS = position_WS;
result.normal_WS = normalize(normal_WS);
return result;
}
@@ -127,9 +125,7 @@ struct VertexAttributes
{
float3 position_MS;
#ifndef POS_ONLY
float3 normal_MS;
float3 tangent_MS;
float3 biTangent_MS;
float4 qTangent;
float3 vertexColor;
float2 texCoords[MAX_TEXCOORDS];
#endif
@@ -142,9 +138,10 @@ struct VertexAttributes
FragmentParameter result;
result.position_CS = clipPos;
#ifndef POS_ONLY
result.tangent_WS = normalize(mul(transformMatrix, float4(tangent_MS, 0)).xyz);
result.biTangent_WS = normalize(mul(transformMatrix, float4(biTangent_MS, 0)).xyz);
result.normal_WS = normalize(mul(transformMatrix, float4(normal_MS, 0)).xyz);
float3x3 tbn = qTangentToMatrix(qTangent);
result.tangent_WS = normalize(mul(transformMatrix, float4(tbn[0], 0)).xyz);
result.biTangent_WS = normalize(mul(transformMatrix, float4(tbn[1], 0)).xyz);
result.normal_WS = normalize(mul(transformMatrix, float4(tbn[2], 0)).xyz);
result.vertexColor = vertexColor;
result.position_WS = worldPos.xyz;
result.texCoords0 = float4(texCoords[0], texCoords[1]);