-
-
Notifications
You must be signed in to change notification settings - Fork 21.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
Scene Shaders - TBN Vector Fixes #100441
Scene Shaders - TBN Vector Fixes #100441
Conversation
f42fad2
to
4d1656b
Compare
servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl
Show resolved
Hide resolved
Supersedes: #78339 #78339 additionally recreates the TBN frame in the fragment shader, but I feel like that part was overkill. The path to getting this merged is twofold:
|
4d1656b
to
e447898
Compare
Fixes two errors related to the normal, tangent, and bitangent vectors, namely normals not always being inverted on backfaces, and normalization being reversed from what MikkTSpace expects.
e447898
to
ed0e3d7
Compare
With help from @hpvb, we've ascertained that VGPR usage actually seems to be the same between this branch and master. I've also rebased away from the style fixes PR, so this is now mergeable as a standalone fix. |
Taking a look at the results in Radeon GPU Analyzer, I can see that this does indeed consume an extra VGPR, however, the VGPR is released before we hit our worst-case allocation section so the number of allocated VGPRs doesn't change (remember, VGPR usage is based on a worst-case allocation strategy). Overall though, you are right, I forgot about the side check. Fixing CULL_DISABLED and CULL_BACK is necessary and this is the way to do it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me!
Thanks! |
Part two of: #100348
Supersedes #78339 sans the anisotropic fixes, which I leave for a future PR dedicated to anisotropy.
Addresses two errors found in the scene shader files that relate to the TBN basis vectors, ie. the vertex normals, tangents, and bitangents/binormals.
First and most important, the normalization of these vectors was reversed from what MikkTSpace expects.
That is to say, the vectors were left unnormalized by the end of the vertex shader, and were normalized early in the fragment shader, whereas MikkTSpace is designed to work with TBN vectors that are normalized prior to vertex interpolation, then left unnormalized for the final tangent-space transformation of the shading normal (which is, itself, subsequently normalized).
Not only is this what's officially advised, as a result it also matches the behaviour of Blender, ensuring that assets made in Blender have their normals reconstructed exactly in Godot.
Second, while the interpolated vertex normal was properly negated on backfaces, this only applied to the subsequent shading normal. Other uses of the vertex normal, such as for applying Normal Bias to shadows, were not inverted, leading to shading errors like the one shown below.
DirectionalLight3D with Bias =
0.01
and Normal Bias =1.0
Note: The left square is a front-facing quad, the right square is back-facing.
bugsquad edit: Fixes: #78343