Tweak pen shader to avoid float precision issues #590
Merged
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.
Resolves
Resolves #589
Resolves #595
Proposed Changes
This PR tweaks the "epsilon" logic used in the shaders to avoid numerical instability and division by zero on low-precision hardware.
Reason for Changes
If you revert #586, the commit message will be dangerously longiOS Safari treats "medium precision" as much lower precision than other browsers, causing some of the pen line formulas to bug out and pen dots to not be drawn. This PR tweaks those formulas to avoid such numerical issues.
As a nice side effect, pen dots' quads will now be rectangular rather than diamond-shaped, which may provide a very slight speed boost.
There's another issue on some??? GPUs where certain calculations in the line shader could overflow the floating-point range if the lines are long enough. I confirmed this on a OnePlus 6T with an Adreno 630 GPU, and someone else reported this on an ARM Chromebook on the Bugs and Glitches forum; not sure where else it may occur.
Test Coverage
Right now there's no way to test shaders across different hardware. It might be a good idea to look into whether that can be done.
I've manually tested this on an iPhone that was buggy before, and it fixes the issue.