-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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 normals of very large SphereMesh
and CapsuleMesh
#98610
Conversation
Ok with the theory of the enhancement. Did not review yet. |
3d9b0c2
to
3365aee
Compare
@fire would you have time now to review this one ? |
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.
That's neat; the rearranging of the equations reduces the precision loss.
I would like someone from the rendering to review the equations, too.
Good. Best if you can ping this person right here then. Thanks ! |
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 good to me. I compared the meshes and their UV channels and they look the same, so the equations are correct
Needs rebase before this can be merged |
Will do tomorrow |
3365aee
to
4c34813
Compare
Here we go |
Thanks! |
SphereMesh
andCapsuleMesh
compute their sphere normals by normalizing the vertex position.Normalizing involves squaring the vertex coordinates, which generate
INFINITE
values if at least one of the coordinates is larger thansqrt(MAX_FLOAT_VALUE)
.With 32 bit floats, this threshold value is ~
1.84E19
. With 64 bit floats it's ~1.34E154
.This PR fixes this behavior by dividing the vertex position by the radius before normalizing.This doesn't change the end result of the normalization, but avoid running into the floating point precision issue.
[EDIT] This PR fixes this behavior by working with unit length vectors all the way down, and scaling with radius only to calculate vertex positions.
Radius is not involved anymore in normal computation logic, which avoids running into the floating point precision issue.
I tested the other primitives and all of them are fine with normals.
SphereMesh
of radius1E28
CapsuleMesh
of radius1E28
Note : I stumbled upon this issue by working on #95944.
Being able to render very large primitives can be useful in very large worlds (space sims, terrain generation ...).