Lipschitz gyroid#90
Open
snowbldr wants to merge 2 commits into
Open
Conversation
The gyroid implicit function
g(p) = sin(kx·x)·cos(ky·y) + sin(ky·y)·cos(kz·z) + sin(kz·z)·cos(kx·x)
is not a true SDF: its gradient has magnitude up to √3·max(kᵢ), so
unrescaled it overstates 3D distance by that factor. The octree
marching-cubes renderer's |sdf(center)| ≥ half-diagonal pruning then
skips cubes that contain the gyroid surface, producing holes.
GyroidSDF3 grows an invStretch field set at construction:
invStretch = 1 / (√3 · max(|kx|, |ky|, |kz|))
Evaluate multiplies its result by invStretch, giving a Lipschitz-1
scalar field with the same zero level set — safe for octree pruning.
render/gyroid_test.go: watertight tests on box-clipped gyroid at four
scale configurations (isotropic 2 and 3, anisotropic 2-3-4, fine 1) at
80 cells, asserting zero boundary edges.
8 scale configurations (isotropic from 0.7 to 5, plus 3 anisotropic including an extreme case where one axis dominates kMax) clipped by a Box3D — exercises the √3·max(kᵢ) bound across the full range of gyroid frequencies. Plus a separate test that fixes the gyroid scale and varies the clipping shape (sphere, rounded box, cylinder, shell-via-difference) so the gyroid surface meets different boundary geometries. All assert zero boundary edges from the octree at cells=80.
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.
Fix Gyroid3D Lipschitz under-correction
Fixes one of the bugs in #85.
The bug
Gyroid3Dreturns the gyroid implicit functionwhich is not a signed distance function —
|∇g|is bounded by√3·max(kᵢ)(tight for isotropic scales), not by 1. The octreemarching-cubes renderer treats
Evaluateas a Lipschitz-1 distanceestimator and prunes cubes via
|sdf(center)| ≥ half-diagonal. Becausegis up to√3·max(kᵢ)larger than the true distance, the pruningrule wrongly skips cubes that contain the gyroid surface, producing
holes.
The uniform renderer is fine — it evaluates every cube — so the bug
only shows up under octree.
The fix
GyroidSDF3grows aninvStretch float64field set at construction:Evaluatemultiplies its result byinvStretch, producing aLipschitz-1 scalar field with the same zero level set — the gyroid
surface is unchanged, just the magnitudes scale down enough that
octree pruning becomes sound.
Tests
render/gyroid_test.goclips the (infinite) gyroid with a 10×10×10box and renders via the octree at 80 cells, asserting zero boundary
edges across four scale configurations:
isotropic_2,isotropic_3— symmetric scalesanisotropic_2_3_4— non-isotropic, exerciseskMaxselectionfine_1— high-frequency case wherekMaxis largeAll pass on macOS.
Architecture-specific note
Same family of bug as the high-taper screw rendering issue from #84 —
non-1-Lipschitz SDF that the octree's
isEmptyrule wrongly trusts.The conservative
√3·max(kᵢ)bound is loose enough to absorb 1-ulpFMA/FTZ rounding differences between architectures, so this should
pass equally on x86_64 and Apple Silicon.