Skip to content

feat(authoring): add stochastic-local-search terrain deformation (#409) - #441

Open
barrulus wants to merge 1 commit into
devfrom
409-feat-add-stochastic-local-search-fractal-terrain-deformation-algorithm
Open

feat(authoring): add stochastic-local-search terrain deformation (#409)#441
barrulus wants to merge 1 commit into
devfrom
409-feat-add-stochastic-local-search-fractal-terrain-deformation-algorithm

Conversation

@barrulus

@barrulus barrulus commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Closes #409

Implements the constraint-based terrain deformation of Stachniak & Stuerzlinger, An Algorithm for Automated Fractal Terrain Deformation (WSCG 2005), as hmap::sls_deformation() in the authoring module.

What's in

  • sls_deformation(): deforms a heightmap by a sequence of truncated-Gaussian pushes (location, amplitude, radius) chosen by stochastic local search to minimise a per-vertex fitness sum. One push per iteration; the best candidate is applied with probability p_best (0.65 as in the paper), otherwise one of the top_fraction best. The slope limit talus_max * radius implements the paper's frequency limitation.
  • DeformationConstraint {target, weight, MATCH | ABOVE | BELOW, scale}: combinable fitness terms covering the paper's cases (match a heightmap, shape mask, fixed road, edge matching), see the header docs.
  • GaussianPush + apply_gaussian_pushes(): the applied sequence can be recorded and replayed (paper §4.5).
  • 11 gtests, example ex_sls_deformation (star island + S-shaped road at 512², a few seconds per run), docs/images/ex_sls_deformation.png.

Deviations from the paper

  • The push amplitude is the least-squares optimum of the local quadratic penalty over the kernel footprint (exact for MATCH terms, active set for one-sided terms), clamped by the slope limit, instead of sampling 25 heights.
  • Candidate vertices: half on a jittered uniform grid, half sampled proportionally to the current penalty map, instead of quad-tree refinement around features.
  • The confidence-based prediction optimisation is not implemented.

CPU only (OpenMP over candidates); a GPU variant or applying several non-overlapping pushes per iteration would be natural follow-ups.

ex_sls_deformation

… tests and example (#409)

Implements the constraint-based terrain deformation of Stachniak &
Stuerzlinger, "An Algorithm for Automated Fractal Terrain Deformation"
(WSCG 2005): a heightmap is deformed by a sequence of truncated-Gaussian
pushes (location, amplitude, radius) chosen by stochastic local search to
minimise a per-vertex fitness sum. Constraints are combinable terms
(target, weight, MATCH/ABOVE/BELOW, scale) covering the paper's
shape-mask, fixed-road and edge-matching cases.

Deviations from the paper: the push amplitude is the least-squares
optimum of the local quadratic penalty over the kernel footprint (clamped
by the slope limit) instead of a sampled set; candidate vertices come from
a jittered grid plus penalty-weighted sampling instead of quad-tree
refinement; the confidence-based prediction optimisation is not
implemented.

Also adds apply_gaussian_pushes() to replay a recorded push sequence.
@barrulus
barrulus requested a review from otto-link as a code owner September 5, 2026 11:01
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