-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly transform normals for non-uniform scales #2049
Conversation
Three naive questions:
|
|
Great, sounds like a perfectly reasonable optimization then. Thanks for the explanation :) |
There's a scenario that I haven't considered, yet, sorry. |
It would also be worth investigating how other popular engines approach this calculation. It seems like they must be doing it by default, so its probably just a matter of peeking at their shaders. I'm familiar with godot's code, so I can just link to the relevant bit: |
@cart thanks for the input and link. I did take a look at Godot's shader code but to be honest, it doesn't look quite right to me. Taking things to the editor seems to confirm this (unless the bitflag of the shader needs to be enabled manually somehow): As mentioned in my comment above, to my knowledge Also, I'll likely keep this as a draft until some things around #1755 are cleared up. |
Closing, since this is for the old renderer and the new one already does this correctly. |
This changes the way normals are transformed in the vertex shader of bevy_pbr. In order to correctly transform normals, the scaling actually has to be applied inversely (see this explanation for details). Otherwise non-uniform scales will produces incorrect normals.
My proposed change comes with the assumption that the
Model
matrix is orthogonal (i.e. does not contain shearing). This allows for some optimization, I can explain more if needed.Here's a pancaked version of
load_gltf
as comparison:screenshot
Since this is just a minor change I didn't bother creating an issue. Feel free to close if the solution doesn't seem fit.