NAME
ttypt/chaff_surf.h - Canonical Continuous Multi-Scale 2D Surface Field.
SYNOPSIS
#include <stdint.h>
#include <stddef.h>
#include <math.h>
Data Structures
Flat, pointer-free multi-scale surface descriptor (maps directly to GLSL UBO).
Continuous scalar value plus exact analytical world-space gradient.
Macros
Maximum number of octaves evaluated in a surface cascade.
Multiplicative prime constant used to derive per-octave seeds.
XOR salt used to derive the Y-channel domain warp seed.
Surface cascade flag: disable domain warp even if warp_amp > 0.
Functions
Bit-exact 8-byte XXH32-style hash on full 32-bit integer lattice coordinates (ix, iy).
Continuous C2-quintic Nyquist low-pass transfer weight L(wavelength, step_wu) in [0, 1].
Exact additive complementary Nyquist band-pass weight.
Compute exact integer torus cell count for an octave of shift shift.
Wrap signed integer cell coordinate c into [0, n) (or return c if n == 0).
Branch-minimal inline floor-to-int32 for bounded floats.
Irrational-spaced fractional phase offset per octave in [0, 1).
Single-octave 2D C2-quintic periodic gradient noise with exact analytical world-space gradient.
Evaluate the torus-periodic 2D domain warp vector w(p) and its 2x2 Jacobian J = [[1 + dwx/dx, dwx/dy], [dwy/dx, 1 + dwy/dy]].
Evaluate the continuous multi-scale surface at split (int32 + float) world coordinates with Nyquist low-pass step step_wu (0.0f = unfiltered).
Evaluate the continuous multi-scale surface at double-precision world coordinates (wx, wy).
Evaluate the continuous multi-scale surface at integer world coordinates (wx, wy).
Complementary sub-texel band-pass evaluator matching GLSL chaff_eval_surf_band.
Complementary sub-texel band-pass evaluator at double-precision world coordinates (wx, wy).
4-wide batch evaluator bit-exact with 4 calls to chaff_surf_eval_i32().
Scanline row evaluator over a uniform X span [ox, ox + span_w] at constant wy.
O(1) strictly conservative value envelope [out_min, out_max] derived directly from the surface descriptor.
Detailed Description
Canonical Continuous Multi-Scale 2D Surface Field.
LICENSE: BSD-2-Clause Copyright (c) 2026, tty-pt
Single source of truth for continuous multi-scale procedural surfaces in libchaff:
- 1.
- 2D C2-quintic gradient noise with exact analytical (val, dx, dy) and 64-direction uniform isotropic unit gradients (zero value-noise pillowing).
- 2.
- Exact integer torus periodicity: world_span = period_n * 2^period_base_shift, with zero seam across wrap boundaries and irrational per-octave phase offsets.
- 3.
- Torus-periodic domain warp with exact 2x2 Jacobian chain-rule gradients.
- 4.
- Smooth C2 ridged multifractal blending (1 - sqrt(n^2 + eps^2)) and scale-invariant slope-damped erosion (1 / (1 + k * |grad|^2)).
- 5.
- Exact additive Nyquist partition of unity: L(lambda, coarse) + max(0, L(lambda, fine) - L(lambda, coarse)) == L(lambda, fine)
- 6.
- One flat data descriptor (chaff_surf_t) drives:
- •
- scalar eval (chaff_surf_eval, chaff_surf_eval_i32, chaff_surf_eval_band)
- •
- 4-wide batch (chaff_surf_eval_i32_4x)
- •
- scanline row eval (chaff_surf_eval_row_i32)
- •
- exact O(1) conservative bounds (chaff_surf_bounds)
- •
- GPU GLSL ES 3.0 UBO evaluator (CHAFF_GLSL_SURF_FN in chaff_glsl.h)
Pure C99, zero heap allocations, zero domain/game constants.
Function Documentation
float chaff_bandpass_f (float wavelength, float fine_step_wu, float coarse_step_wu) [inline], [static]
Exact additive complementary Nyquist band-pass weight. B(lambda; fine_step, coarse_step) = max(0, L(lambda, fine_step) - L(lambda, coarse_step)). Satisfies exact partition of unity for ALL fine_step <= coarse_step and ALL wavelengths: L(lambda, coarse_step) + B(lambda; fine_step, coarse_step) == L(lambda, fine_step)
int32_t chaff_fast_floor_i32 (float x) [inline], [static]
Branch-minimal inline floor-to-int32 for bounded floats. Avoids libm floorf@PLT register spills inside the octave loop on baseline x86_64 SSE2 targets.
chaff_eval_t chaff_grad_octave_2d (int32_t wx_i, float wx_f, int32_t wy_i, float wy_f, uint8_t shift, uint32_t nx, uint32_t ny, uint32_t seed) [inline], [static]
Single-octave 2D C2-quintic periodic gradient noise with exact analytical world-space gradient. Input coordinate is split as exact integer world units (wx_i, wy_i) + float offset (wx_f, wy_f) so precision remains full 24-bit intra-cell even at Earth-scale coordinates (~10^9 wu). Output value is strictly in [-1.0, +1.0]; (dx, dy) is in value-per-world-unit.
uint32_t chaff_hash2i (int32_t ix, int32_t iy, uint32_t seed) [inline], [static]
Bit-exact 8-byte XXH32-style hash on full 32-bit integer lattice coordinates (ix, iy). Zero 16-bit wrap collision even on Earth-scale (b=23) planets. Matches GLSL chaff_hash2i.
float chaff_lowpass_f (float wavelength, float step_wu) [inline], [static]
Continuous C2-quintic Nyquist low-pass transfer weight L(wavelength, step_wu) in [0, 1].
- step_wu <= 0 -> 1.0 (unfiltered point sample)
- wavelength <= 2*step_wu -> 0.0 (sub-Nyquist, skip octave)
- wavelength >= 4*step_wu -> 1.0 (fully resolved)
void chaff_octave_phase (uint8_t shift, float * out_px, float * out_py) [inline], [static]
Irrational-spaced fractional phase offset per octave in [0, 1). Prevents octave lattice lines from aligning across scales while preserving exact torus wrap.
uint32_t chaff_surf_axis_cells (uint32_t period_n, uint8_t period_base_shift, uint8_t shift) [inline], [static]
Compute exact integer torus cell count for an octave of shift shift. Returns 0 for an axis if aperiodic or if cell count overflows int32.
void chaff_surf_bounds (const chaff_surf_t * c, float step_wu, float * out_min, float * out_max) [inline], [static]
O(1) strictly conservative value envelope [out_min, out_max] derived directly from the surface descriptor. Guaranteed to contain chaff_surf_eval() for all (wx, wy).
chaff_eval_t chaff_surf_eval_band_split (const chaff_surf_t * c, int32_t wx_i, float wx_f, int32_t wy_i, float wy_f, float fine_step_wu, float coarse_step_wu, float seed_gx, float seed_gy) [inline], [static]
Complementary sub-texel band-pass evaluator matching GLSL chaff_eval_surf_band. Evaluates strictly the octaves resolved between fine_step_wu and coarse_step_wu using additive partition-of-unity weight max(0, L(lambda, fine) - L(lambda, coarse)).
Author
Generated automatically by Doxygen for chaff from the source code.