diff --git a/shaders/vk14/skin.comp b/shaders/vk14/skin.comp index 2f26b9130..7f5d8846e 100644 --- a/shaders/vk14/skin.comp +++ b/shaders/vk14/skin.comp @@ -64,7 +64,12 @@ void main() } vec3 position = (blended * vec4(source.position_u.xyz, 1.0)).xyz; mat3 rotation = mat3(blended); - vec3 normal = skin_direction(rotation, source.normal_v.xyz); + // the normals by the cofactors of the rotation (the direction of its inverse transpose), with the sign of its determinant, + // as skinning::skin_vertices() moves them on the cpu + mat3 cofactors = mat3(cross(rotation[1], rotation[2]), cross(rotation[2], rotation[0]), cross(rotation[0], rotation[1])); + if (dot(rotation[0], cofactors[0]) < 0.0) + cofactors = -cofactors; + vec3 normal = skin_direction(cofactors, source.normal_v.xyz); vec3 tangent = skin_direction(rotation, source.tangent.xyz); uint target = (skin_counts.y + index) * 12u; skin_output[target + 0u] = position.x;