Skip to content

Commit

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

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

## Solution

- In #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 committed Nov 11, 2022
1 parent 99c815f commit c4e791d
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 c4e791d

Please sign in to comment.