Skip to content

Commit

Permalink
adjoint matrix fix (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij authored Dec 13, 2024
1 parent 275e5f3 commit 163a94c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions WickedEngine/shaders/objectHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/shaders/objectHF_mesh_shading.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/shaders/paintdecalVS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/shaders/renderlightmapVS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 6 additions & 6 deletions WickedEngine/shaders/surfaceHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/shaders/wetmap_updateCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 163a94c

Please sign in to comment.