[Merged by Bors] - bevy_pbr: Normalize skinned normals#6543
Closed
superdump wants to merge 2 commits intobevyengine:mainfrom
Closed
[Merged by Bors] - bevy_pbr: Normalize skinned normals#6543superdump wants to merge 2 commits intobevyengine:mainfrom
superdump wants to merge 2 commits intobevyengine:mainfrom
Conversation
This was forgotten in bevyengine#5666 when normalization of normals was moved from the fragment to vertex stage.
This was referenced Nov 10, 2022
Contributor
Author
This should be the correct fix. But I want it to see some testing. As noted in the comment from the code, normalization is not meant to be applied to all normals in the fragment shader before normal mapping. It may be that we should make sure to normalise all normals at the end of the apply_normal_mapping() function though and that may be more difficult to find errors with so maybe I'll add that... |
Contributor
Author
|
So the remaining bit that I'm unsure of is whether perspective correct interpolation causes normals to be significantly scaled such that they are no longer unit normals. The safe bet then would be: diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl
index 58eb7023e..3e9046353 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 |
Contributor
Author
Contributor
Author
The interpolated world normals were not being re-normalized for the non-normal mapping case.
Contributor
|
This fixes it for me. |
mockersf
approved these changes
Nov 11, 2022
Member
|
bors r+ |
bors bot
pushed a commit
that referenced
this pull request
Nov 11, 2022
# 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.
Contributor
ItsDoot
pushed a commit
to ItsDoot/bevy
that referenced
this pull request
Feb 1, 2023
# 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Objective
Solution
Changelog