adjoint matrix fix (#989)

This commit is contained in:
Turánszki János
2024-12-13 10:49:12 +01:00
committed by GitHub
parent 275e5f3791
commit 163a94ca4e
6 changed files with 12 additions and 12 deletions
+2 -2
View File
@@ -250,11 +250,11 @@ struct VertexSurface
ao = 1;
}
normal = mul(input.GetInstance().transform.GetMatrixAdjoint(), normal);
normal = mul(input.GetInstance().transformRaw.GetMatrixAdjoint(), normal);
normal = any(normal) ? normalize(normal) : 0;
tangent = input.GetTangent();
tangent.xyz = mul(input.GetInstance().transform.GetMatrixAdjoint(), tangent.xyz);
tangent.xyz = mul(input.GetInstance().transformRaw.GetMatrixAdjoint(), tangent.xyz);
tangent.xyz = any(tangent.xyz) ? normalize(tangent.xyz) : 0;
uvsets = input.GetUVSets();
@@ -65,7 +65,7 @@ void main(uint3 Gid : SV_GroupID, uint groupIndex : SV_GroupIndex)
if((geometry.flags & SHADERMESH_FLAG_DOUBLE_SIDED) == 0 && geometry.vb_pre < 0) // disable cone culling for double sided and skinned
{
// Cone culling:
bounds.cone_axis = mul(inst.transform.GetMatrixAdjoint(), bounds.cone_axis);
bounds.cone_axis = mul(inst.transformRaw.GetMatrixAdjoint(), bounds.cone_axis);
if (camera.IsOrtho())
{
visible &= dot(camera.forward, bounds.cone_axis) < bounds.cone_cutoff;
+1 -1
View File
@@ -27,7 +27,7 @@ Output main(uint vertexID : SV_VertexID)
{
nor = bindless_buffers_half4[geometry.vb_nor][vertexID].xyz;
}
nor = mul(inst.transform.GetMatrixAdjoint(), nor);
nor = mul(inst.transformRaw.GetMatrixAdjoint(), nor);
float2 uv = 0;
[branch]
+1 -1
View File
@@ -28,7 +28,7 @@ Output main(uint vertexID : SV_VertexID)
output.pos3D = mul(inst.transform.GetMatrix(), float4(pos, 1)).xyz;
output.normal = mul(inst.transform.GetMatrixAdjoint(), nor);
output.normal = mul(inst.transformRaw.GetMatrixAdjoint(), nor);
return output;
}
+6 -6
View File
@@ -376,9 +376,9 @@ struct Surface
if (geometry.vb_nor >= 0)
{
Buffer<float4> buf = bindless_buffers_float4[NonUniformResourceIndex(geometry.vb_nor)];
float3 n0 = mul(inst.transform.GetMatrixAdjoint(), buf[i0].xyz);
float3 n1 = mul(inst.transform.GetMatrixAdjoint(), buf[i1].xyz);
float3 n2 = mul(inst.transform.GetMatrixAdjoint(), buf[i2].xyz);
float3 n0 = mul(inst.transformRaw.GetMatrixAdjoint(), buf[i0].xyz);
float3 n1 = mul(inst.transformRaw.GetMatrixAdjoint(), buf[i1].xyz);
float3 n2 = mul(inst.transformRaw.GetMatrixAdjoint(), buf[i2].xyz);
n0 = any(n0) ? normalize(n0) : 0;
n1 = any(n1) ? normalize(n1) : 0;
n2 = any(n2) ? normalize(n2) : 0;
@@ -452,9 +452,9 @@ struct Surface
float4 t0 = buf[i0];
float4 t1 = buf[i1];
float4 t2 = buf[i2];
t0.xyz = mul(inst.transform.GetMatrixAdjoint(), t0.xyz);
t1.xyz = mul(inst.transform.GetMatrixAdjoint(), t1.xyz);
t2.xyz = mul(inst.transform.GetMatrixAdjoint(), t2.xyz);
t0.xyz = mul(inst.transformRaw.GetMatrixAdjoint(), t0.xyz);
t1.xyz = mul(inst.transformRaw.GetMatrixAdjoint(), t1.xyz);
t2.xyz = mul(inst.transformRaw.GetMatrixAdjoint(), t2.xyz);
t0.xyz = any(t0.xyz) ? normalize(t0.xyz) : 0;
t1.xyz = any(t1.xyz) ? normalize(t1.xyz) : 0;
t2.xyz = any(t2.xyz) ? normalize(t2.xyz) : 0;
+1 -1
View File
@@ -20,7 +20,7 @@ void main(uint DTid : SV_DispatchThreadID)
{
Buffer<half4> vb_nor = bindless_buffers_half4[geometry.vb_nor];
half3 normal = vb_nor[DTid].xyz;
normal = mul(meshinstance.transform.GetMatrixAdjoint(), normal);
normal = mul(meshinstance.transformRaw.GetMatrixAdjoint(), normal);
normal = normalize(normal);
drying *= lerp(4, 1, pow8(saturate(normal.y))); // modulate drying speed based on surface slope
}