From d6de3f43bc83102ff418a7c54c9a84639489a126 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Thu, 10 Nov 2022 23:01:49 +0100 Subject: [PATCH 1/2] bevy_pbr: Normalize skinned normals This was forgotten in #5666 when normalization of normals was moved from the fragment to vertex stage. --- crates/bevy_pbr/src/render/skinning.wgsl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/bevy_pbr/src/render/skinning.wgsl b/crates/bevy_pbr/src/render/skinning.wgsl index 9fe80c904163d..8332d0161347a 100644 --- a/crates/bevy_pbr/src/render/skinning.wgsl +++ b/crates/bevy_pbr/src/render/skinning.wgsl @@ -30,9 +30,13 @@ fn skin_normals( model: mat4x4, normal: vec3, ) -> vec3 { - return inverse_transpose_3x3(mat3x3( - model[0].xyz, - model[1].xyz, - model[2].xyz - )) * normal; + return normalize( + inverse_transpose_3x3( + mat3x3( + model[0].xyz, + model[1].xyz, + model[2].xyz + ) + ) * normal + ); } From 3df1edcbdab407261ae692510503b786042ea72b Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Thu, 10 Nov 2022 23:54:19 +0100 Subject: [PATCH 2/2] bevy_pbr: Ensure lighting normals are normalized in all cases The interpolated world normals were not being re-normalized for the non-normal mapping case. --- crates/bevy_pbr/src/render/pbr_functions.wgsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index 58eb7023e7243..3e90463534163 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -91,12 +91,12 @@ fn apply_normal_mapping( // calculates the normal maps so there is no error introduced. Do not change this code // unless you really know what you are doing. // http://www.mikktspace.com/ - N = normalize(Nt.x * T + Nt.y * B + Nt.z * N); + N = Nt.x * T + Nt.y * B + Nt.z * N; #endif #endif #endif - return N; + return normalize(N); } // NOTE: Correctly calculates the view vector depending on whether