Fix MatrixHelper producing slightly different results from vanilla #2169
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Vanilla uses JOML's
Vector4f#mul
orVector3f#mul
methods to apply matrix transformations to vectors. The implementation of these methods uses calls likeand the
Math.fma
wrappers have the effect of doing the final additions right-to-left, rather than left-to-right. Since Sodium'sMatrixHelper
uses left-to-right addition, the value it produces might differ very slightly from JOML's as a result of floating-point precision errors. This can cause Z-fighting.The solution I used is to simply add brackets to force the additions to be performed in the same order as JOML.
Discord thread where the issue was reported: https://discord.com/channels/602796788608401408/1174666147828879400
The user and I both tested & confirmed this fixes their issue.