Make sphere and circle seam vertices bit-exact - #281
Open
jkrumbiegel wants to merge 1 commit into
Open
Conversation
Sphere and Circle tessellations duplicate the wrap-seam vertices (the u = 0 and u = 1 columns) on purpose, so that texture coordinates can differ across the seam. But parametrizing with cos/sin over LinRange(0, 2pi, n) evaluates the seam columns at 0 and 2pi, whose results differ by float rounding (e.g. cos(2pi) = 0.99999994f0 in Float32). Renderers that classify mesh edges by exact position matching (e.g. Makie's edge stroking in MakieOrg/Makie.jl#5727) then see the seam as a mesh boundary and draw it differently. Parametrize with cospi/sinpi over LinRange(0, 2, n) instead, which evaluates the wrap exactly: cospi(2.0) === 1.0 and sinpi(2.0) === 0.0. This also makes all pole-row vertices of the sphere bit-identical (sinpi(1.0) === 0.0, so the bottom pole no longer scatters by cos(phi) * 1.2e-16) and slightly improves accuracy of all other vertices. Cylinder and Cone reuse seam vertices via mod1 indexing and are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Sphere and Circle tessellations duplicate the wrap-seam vertices on purpose (so texture coordinates can differ across the seam), but with the
cos/sinoverLinRange(0, 2pi, n)parametrization the two seam columns evaluate at 0 and 2pi and end up differing by float rounding (cos(2pi) == 0.99999994f0in Float32). Renderers that classify mesh edges by exact position matching, like the edge stroking in MakieOrg/Makie.jl#5727, then see the seam as a mesh boundary and stroke it at full width instead of half.This switches the parametrization to
cospi/sinpioverLinRange(0, 2, n), which evaluates the wrap exactly (cospi(2.0) === 1.0,sinpi(2.0) === 0.0), so the seam columns are bit-identical while staying separate vertices. It also makes the sphere's pole rows bit-identical (previously the bottom pole vertices scattered bycos(phi) * sin(pi) ≈ 1.2e-16) and slightly improves the accuracy of all other vertices. Cylinder and Cone already reuse their seam vertices viamod1indexing and are unaffected.