Skip to content

Commit

Permalink
bevy_pbr: Normalize skinned normals (bevyengine#6543)
Browse files Browse the repository at this point in the history
# Objective

- Make the many foxes not unnecessarily bright. Broken since bevyengine#5666.
- Fixes bevyengine#6528 

## Solution

- In bevyengine#5666 normalisation of normals was moved from the fragment stage to the vertex stage. However, it was not added to the vertex stage for skinned normals. The many foxes are skinned and their skinned normals were not unit normals. which made them brighter. Normalising the skinned normals fixes this.

---

## Changelog

- Fixed: Non-unit length skinned normals are now normalized.
  • Loading branch information
superdump authored and ItsDoot committed Feb 1, 2023
1 parent ecc7c22 commit 7c877d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/render/pbr_functions.wgsl
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions crates/bevy_pbr/src/render/skinning.wgsl
Expand Up @@ -30,9 +30,13 @@ fn skin_normals(
model: mat4x4<f32>,
normal: vec3<f32>,
) -> vec3<f32> {
return inverse_transpose_3x3(mat3x3<f32>(
model[0].xyz,
model[1].xyz,
model[2].xyz
)) * normal;
return normalize(
inverse_transpose_3x3(
mat3x3<f32>(
model[0].xyz,
model[1].xyz,
model[2].xyz
)
) * normal
);
}

0 comments on commit 7c877d3

Please sign in to comment.