Skip to content

Make sphere and circle seam vertices bit-exact - #281

Open
jkrumbiegel wants to merge 1 commit into
JuliaGeometry:masterfrom
jkrumbiegel:jk/exact-sphere-seam
Open

Make sphere and circle seam vertices bit-exact#281
jkrumbiegel wants to merge 1 commit into
JuliaGeometry:masterfrom
jkrumbiegel:jk/exact-sphere-seam

Conversation

@jkrumbiegel

Copy link
Copy Markdown

Sphere and Circle tessellations duplicate the wrap-seam vertices on purpose (so texture coordinates can differ across the seam), but with the cos/sin over LinRange(0, 2pi, n) parametrization the two seam columns evaluate at 0 and 2pi and end up differing by float rounding (cos(2pi) == 0.99999994f0 in 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/sinpi over LinRange(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 by cos(phi) * sin(pi) ≈ 1.2e-16) and slightly improves the accuracy of all other vertices. Cylinder and Cone already reuse their seam vertices via mod1 indexing and are unaffected.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant