normal compression makes shading look terrible

This commit is contained in:
Dynamitos
2025-01-29 16:29:58 +01:00
parent e5ac354527
commit 09660ab642
6 changed files with 84 additions and 80 deletions
+8 -5
View File
@@ -125,7 +125,10 @@ struct VertexAttributes
{
float3 position_MS;
#ifndef POS_ONLY
float4 qTangent;
//float4 qTangent;
float3 normal_MS;
float3 tangent_MS;
float3 biTangent_MS;
float3 vertexColor;
float2 texCoords[MAX_TEXCOORDS];
#endif
@@ -138,10 +141,10 @@ struct VertexAttributes
FragmentParameter result;
result.position_CS = clipPos;
#ifndef POS_ONLY
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);
//float3x3 tbn = qTangentToMatrix(qTangent);
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);
result.vertexColor = vertexColor;
result.position_WS = worldPos.xyz;
result.texCoords0 = float4(texCoords[0], texCoords[1]);
+7 -6
View File
@@ -14,9 +14,10 @@ struct StaticMeshVertexData
VertexAttributes attributes;
attributes.position_MS = float3(positions[index * 3 + 0], positions[index * 3 + 1], positions[index * 3 + 2]);
#ifndef POS_ONLY
attributes.qTangent = qTangent[index];
//attributes.tangent_MS = float3(tangents[index * 3 + 0], tangents[index * 3 + 1], tangents[index * 3 + 2]);
//attributes.biTangent_MS = float3(biTangents[index * 3 + 0], biTangents[index * 3 + 1], biTangents[index * 3 + 2]);
//attributes.qTangent = qTangent[index];
attributes.normal_MS = float3(normals[index * 3 + 0], normals[index * 3 + 1], normals[index * 3 + 2]);
attributes.tangent_MS = float3(tangents[index * 3 + 0], tangents[index * 3 + 1], tangents[index * 3 + 2]);
attributes.biTangent_MS = float3(biTangents[index * 3 + 0], biTangents[index * 3 + 1], biTangents[index * 3 + 2]);
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
attributes.texCoords[i] = float2(uint16ToFloat(texCoords[i][index * 2 + 0]), uint16ToFloat(texCoords[i][index * 2 + 1]));
@@ -26,9 +27,9 @@ struct StaticMeshVertexData
return attributes;
}
StructuredBuffer<float> positions;
StructuredBuffer<float4> qTangent;
//StructuredBuffer<float> tangents;
//StructuredBuffer<float> biTangents;
StructuredBuffer<float> normals;
StructuredBuffer<float> tangents;
StructuredBuffer<float> biTangents;
StructuredBuffer<uint16_t> color;
StructuredBuffer<uint16_t> texCoords[MAX_TEXCOORDS];
};
+1 -1
View File
@@ -71,7 +71,7 @@ import MATERIAL_FILE_NAME;
*/
const float eps = 1e-5;
static const float eps = 1e-5;
[shader("closesthit")]
void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttributes attr)
{