-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Fix AABB computation for position compression to not depend on vertex order #93916
Conversation
I initially discovered this issue on several meshes when looking into issue 93587 (something like 5 out of 100 unique meshes there have this problem). Since then I also found other simpler meshes that reproduce it, for example PotOfCoals (https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/PotOfCoals): What happens here is that the depth prepass uses shadow mesh which uses a separate vertex buffer that has been compressed independently; during compression, floating point drift results in a slightly different AABB which then, for some vertices, results in a different rounding direction - the u16 position components for black vertices that are in the center of the black patch are 1-off from the version used in the color pass. This results in the color rendering failing the depth test, and the clear color - black here - remains. This doesn't affect mobile renderer because it doesn't enable depth prepass as far as I can tell. After fixing this the rendering of this mesh, as well as other affected meshes, is now proper (after reimport): |
0533cd0
to
f1d839a
Compare
Two additional issues that I've discovered while debugging all of this that someone might want to pick up:
|
Great spot. 👍 As in 3.x, this is so common, I'd be wondering whether to add to Doing this from raw pointer + length is a pain point in Godot as we don't have things like
then doing the I bet you'll find this is already used in a few places throughout the codebase already which can also be converted (maybe in 2nd PR). This was the case in 3.x. Coding convention wise we use |
… order The previous computation was dependent on the vertex order in two ways: - If the first vertex was on the AABB boundary, the AABB would be increased by the epsilon due to size clamping - Every time the AABB would get expanded, we would recompute end from size and reconstruct size again, which resulted in slow floating point drift. In isolation this may not seem like it matters, but it means that the same mesh with a different vertex order may result in a slightly different AABB. This can be a significant issue due to shadow meshes and their use in depth prepass: shadow meshes reorder vertex data as part of the deduplication process, as they append one unique position at a time and as such remove the duplicate positions; this can result in a different AABB which would result in a different reconstructed vertex position during a depth pre-pass, causing mesh self-occlusion.
Fixed code style in place for now and moved min_size outside of the function. |
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.
Actually this is likely fine for now, we can look at moving to AABB in separate PR if there's support.
Thanks! |
The previous computation was dependent on the vertex order in two ways:
In isolation this may not seem like it matters, but it means that the same mesh with a different vertex order may result in a slightly different AABB. This can be a significant issue due to shadow meshes and their use in depth prepass: shadow meshes reorder vertex data as part of the deduplication process, as they append one unique position at a time and as such remove the duplicate positions; this can result in a different AABB which would result in a different reconstructed vertex position during a depth pre-pass, causing mesh self-occlusion.
Bugsquad edit: Fixes #91962