[Merged by Bors] - bevy_pbr: Fix tangent and normal normalization#5666
[Merged by Bors] - bevy_pbr: Fix tangent and normal normalization#5666superdump wants to merge 3 commits intobevyengine:mainfrom
Conversation
Morten Mikkelsen clarified that the world normal and tangent must be normalized in the vertex stage and the interpolated values must not be normalized in the fragment stage.
|
Before merging this I want to add comments about why things are done this way. |
|
I hacked the Kapture.2022-08-13.at.12.41.38.mp4On this PR it looks like this: Kapture.2022-08-13.at.12.39.15.mp4 |
Done. |
|
bors try |
|
It seems there is possibly one more detail. Morten Mikkelsen says that if the determinant of the local to world matrix can be negative (I think it definitely can be) then something needs scaling by the sign of the determinant. Just finding out exactly what, then I’ll update the PR. |
If the sign of the determinant of the 3x3 model matrix is negative, this must be applied when calculating the bitangent from the cross-product of the interpolated world space normal and interpolated world space tangent. This information came from Morten Mikkelsen and can be understood from section 2 of the following paper, though I do not understand it well enough to be able to explain it: https://jcgt.org/published/0009/03/04/
cart
left a comment
There was a problem hiding this comment.
Seems to work with both uniform and non-uniform scales!
|
bors r+ |
# Objective - Morten Mikkelsen clarified that the world normal and tangent must be normalized in the vertex stage and the interpolated values must not be normalized in the fragment stage. This is in order to match the mikktspace approach exactly. - Fixes #5514 by ensuring the tangent basis matrix (TBN) is orthonormal ## Solution - Normalize the world normal in the vertex stage and not the fragment stage - Normalize the world tangent xyz in the vertex stage - Take into account the sign of the determinant of the local to world matrix when calculating the bitangent --- ## Changelog - Fixed - scaling a model that uses normal mapping now has correct lighting again
|
Pull request successfully merged into main. Build succeeded: |
# Objective - Morten Mikkelsen clarified that the world normal and tangent must be normalized in the vertex stage and the interpolated values must not be normalized in the fragment stage. This is in order to match the mikktspace approach exactly. - Fixes #5514 by ensuring the tangent basis matrix (TBN) is orthonormal ## Solution - Normalize the world normal in the vertex stage and not the fragment stage - Normalize the world tangent xyz in the vertex stage - Take into account the sign of the determinant of the local to world matrix when calculating the bitangent --- ## Changelog - Fixed - scaling a model that uses normal mapping now has correct lighting again
…)" This reverts commit a7ece4c.
…)" This reverts commit 681c9c6.
…)" This reverts commit 681c9c6.
# Objective - Morten Mikkelsen clarified that the world normal and tangent must be normalized in the vertex stage and the interpolated values must not be normalized in the fragment stage. This is in order to match the mikktspace approach exactly. - Fixes bevyengine#5514 by ensuring the tangent basis matrix (TBN) is orthonormal ## Solution - Normalize the world normal in the vertex stage and not the fragment stage - Normalize the world tangent xyz in the vertex stage - Take into account the sign of the determinant of the local to world matrix when calculating the bitangent --- ## Changelog - Fixed - scaling a model that uses normal mapping now has correct lighting again
# Objective - Morten Mikkelsen clarified that the world normal and tangent must be normalized in the vertex stage and the interpolated values must not be normalized in the fragment stage. This is in order to match the mikktspace approach exactly. - Fixes bevyengine#5514 by ensuring the tangent basis matrix (TBN) is orthonormal ## Solution - Normalize the world normal in the vertex stage and not the fragment stage - Normalize the world tangent xyz in the vertex stage - Take into account the sign of the determinant of the local to world matrix when calculating the bitangent --- ## Changelog - Fixed - scaling a model that uses normal mapping now has correct lighting again
This was forgotten in bevyengine#5666 when normalization of normals was moved from the fragment to vertex stage.
# 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.
…)" This reverts commit 681c9c6.
…)" This reverts commit 681c9c6.
…)" This reverts commit 681c9c6.
…)" This reverts commit 681c9c6.
…)" This reverts commit 681c9c6.
# Objective - Morten Mikkelsen clarified that the world normal and tangent must be normalized in the vertex stage and the interpolated values must not be normalized in the fragment stage. This is in order to match the mikktspace approach exactly. - Fixes bevyengine#5514 by ensuring the tangent basis matrix (TBN) is orthonormal ## Solution - Normalize the world normal in the vertex stage and not the fragment stage - Normalize the world tangent xyz in the vertex stage - Take into account the sign of the determinant of the local to world matrix when calculating the bitangent --- ## Changelog - Fixed - scaling a model that uses normal mapping now has correct lighting again
# 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 reverts commit 681c9c6.
…)" This reverts commit 681c9c6.
…)" This reverts commit 681c9c6.
Objective
Solution
Changelog