.TH "ttypt/chaff_surf.h" 3 "chaff" \" -*- nroff -*- .ad l .nh .SH NAME ttypt/chaff_surf.h \- Canonical Continuous Multi-Scale 2D Surface Field\&. .SH SYNOPSIS .br .PP \fR#include \fP .br \fR#include \fP .br \fR#include \fP .br .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBchaff_surf_t\fP" .br .RI "Flat, pointer-free multi-scale surface descriptor (maps directly to GLSL UBO)\&. " .ti -1c .RI "struct \fBchaff_eval_t\fP" .br .RI "Continuous scalar value plus exact analytical world-space gradient\&. " .in -1c .SS "Macros" .in +1c .ti -1c .RI "#define \fBCHAFF_SURF_MAX_OCTAVES\fP 24u" .br .RI "Maximum number of octaves evaluated in a surface cascade\&. " .ti -1c .RI "#define \fBCHAFF_SURF_SEED_PRIME\fP 0x85EBCA77u" .br .RI "Multiplicative prime constant used to derive per-octave seeds\&. " .ti -1c .RI "#define \fBCHAFF_SURF_WARP_Y_SALT\fP 0x9E3779B9u" .br .RI "XOR salt used to derive the Y-channel domain warp seed\&. " .ti -1c .RI "#define \fBCHAFF_SURF_FLAG_NO_WARP\fP (1u << 1)" .br .RI "Surface cascade flag: disable domain warp even if warp_amp > 0\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "static uint32_t \fBchaff_hash2i\fP (int32_t ix, int32_t iy, uint32_t seed)" .br .RI "Bit-exact 8-byte XXH32-style hash on full 32-bit integer lattice coordinates (\fRix\fP, \fRiy\fP)\&. " .ti -1c .RI "static float \fBchaff_lowpass_f\fP (float wavelength, float step_wu)" .br .RI "Continuous C2-quintic Nyquist low-pass transfer weight L(wavelength, step_wu) in [0, 1]\&. " .ti -1c .RI "static float \fBchaff_bandpass_f\fP (float wavelength, float fine_step_wu, float coarse_step_wu)" .br .RI "Exact additive complementary Nyquist band-pass weight\&. " .ti -1c .RI "static uint32_t \fBchaff_surf_axis_cells\fP (uint32_t period_n, uint8_t period_base_shift, uint8_t shift)" .br .RI "Compute exact integer torus cell count for an octave of shift \fRshift\fP\&. " .ti -1c .RI "static int32_t \fBchaff_wrap_cell_i32\fP (int32_t c, uint32_t n)" .br .RI "Wrap signed integer cell coordinate \fRc\fP into [0, \fRn\fP) (or return \fRc\fP if \fRn\fP == 0)\&. " .ti -1c .RI "static int32_t \fBchaff_fast_floor_i32\fP (float x)" .br .RI "Branch-minimal inline floor-to-int32 for bounded floats\&. " .ti -1c .RI "static void \fBchaff_octave_phase\fP (uint8_t shift, float *out_px, float *out_py)" .br .RI "Irrational-spaced fractional phase offset per octave in [0, 1)\&. " .ti -1c .RI "static \fBchaff_eval_t\fP \fBchaff_grad_octave_2d\fP (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)" .br .RI "Single-octave 2D C2-quintic periodic gradient noise with exact analytical world-space gradient\&. " .ti -1c .RI "static void \fBchaff_surf_eval_warp\fP (const \fBchaff_surf_t\fP *c, int32_t wx_i, float wx_f, int32_t wy_i, float wy_f, float step_wu, float *out_wx, float *out_wy, float *out_dwx_dx, float *out_dwx_dy, float *out_dwy_dx, float *out_dwy_dy)" .br .RI "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]]\&. " .ti -1c .RI "static \fBchaff_eval_t\fP \fBchaff_surf_eval_split\fP (const \fBchaff_surf_t\fP *c, int32_t wx_i, float wx_f, int32_t wy_i, float wy_f, float step_wu)" .br .RI "Evaluate the continuous multi-scale surface at split (int32 + float) world coordinates with Nyquist low-pass step \fRstep_wu\fP (0\&.0f = unfiltered)\&. " .ti -1c .RI "static \fBchaff_eval_t\fP \fBchaff_surf_eval\fP (const \fBchaff_surf_t\fP *c, double wx, double wy, float step_wu)" .br .RI "Evaluate the continuous multi-scale surface at double-precision world coordinates (\fRwx\fP, \fRwy\fP)\&. " .ti -1c .RI "static \fBchaff_eval_t\fP \fBchaff_surf_eval_i32\fP (const \fBchaff_surf_t\fP *c, int32_t wx, int32_t wy, float step_wu)" .br .RI "Evaluate the continuous multi-scale surface at integer world coordinates (\fRwx\fP, \fRwy\fP)\&. " .ti -1c .RI "static \fBchaff_eval_t\fP \fBchaff_surf_eval_band_split\fP (const \fBchaff_surf_t\fP *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)" .br .RI "Complementary sub-texel band-pass evaluator matching GLSL chaff_eval_surf_band\&. " .ti -1c .RI "static \fBchaff_eval_t\fP \fBchaff_surf_eval_band\fP (const \fBchaff_surf_t\fP *c, double wx, double wy, float fine_step_wu, float coarse_step_wu, float seed_gx, float seed_gy)" .br .RI "Complementary sub-texel band-pass evaluator at double-precision world coordinates (\fRwx\fP, \fRwy\fP)\&. " .ti -1c .RI "static void \fBchaff_surf_eval_i32_4x\fP (const \fBchaff_surf_t\fP *c, const int32_t wx[4], const int32_t wy[4], float step_wu, \fBchaff_eval_t\fP out[4])" .br .RI "4-wide batch evaluator bit-exact with 4 calls to \fBchaff_surf_eval_i32()\fP\&. " .ti -1c .RI "static void \fBchaff_surf_eval_row_i32\fP (const \fBchaff_surf_t\fP *c, int32_t wy, int32_t ox, int32_t span_w, uint32_t count, float step_wu, \fBchaff_eval_t\fP *out_row)" .br .RI "Scanline row evaluator over a uniform X span [ox, ox + span_w] at constant \fRwy\fP\&. " .ti -1c .RI "static void \fBchaff_surf_bounds\fP (const \fBchaff_surf_t\fP *c, float step_wu, float *out_min, float *out_max)" .br .RI "O(1) strictly conservative value envelope [out_min, out_max] derived directly from the surface descriptor\&. " .in -1c .SH "Detailed Description" .PP Canonical Continuous Multi-Scale 2D Surface Field\&. LICENSE: BSD-2-Clause Copyright (c) 2026, tty-pt .PP Single source of truth for continuous multi-scale procedural surfaces in libchaff: .IP "1." 4 2D C2-quintic gradient noise with exact analytical (val, dx, dy) and 64-direction uniform isotropic unit gradients (zero value-noise pillowing)\&. .IP "2." 4 Exact integer torus periodicity: world_span = period_n * 2^period_base_shift, with zero seam across wrap boundaries and irrational per-octave phase offsets\&. .IP "3." 4 Torus-periodic domain warp with exact 2x2 Jacobian chain-rule gradients\&. .IP "4." 4 Smooth C2 ridged multifractal blending (1 - sqrt(n^2 + eps^2)) and scale-invariant slope-damped erosion (1 / (1 + k * |grad|^2))\&. .IP "5." 4 Exact additive Nyquist partition of unity: L(lambda, coarse) + max(0, L(lambda, fine) - L(lambda, coarse)) == L(lambda, fine) .IP "6." 4 One flat data descriptor (\fBchaff_surf_t\fP) drives: .IP " \(bu" 4 scalar eval (chaff_surf_eval, chaff_surf_eval_i32, chaff_surf_eval_band) .IP " \(bu" 4 4-wide batch (chaff_surf_eval_i32_4x) .IP " \(bu" 4 scanline row eval (chaff_surf_eval_row_i32) .IP " \(bu" 4 exact O(1) conservative bounds (chaff_surf_bounds) .IP " \(bu" 4 GPU GLSL ES 3\&.0 UBO evaluator (CHAFF_GLSL_SURF_FN in \fBchaff_glsl\&.h\fP) .PP .PP .PP Pure C99, zero heap allocations, zero domain/game constants\&. .SH "Function Documentation" .PP .SS "float chaff_bandpass_f (float wavelength, float fine_step_wu, float coarse_step_wu)\fR [inline]\fP, \fR [static]\fP" .PP 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) .SS "int32_t chaff_fast_floor_i32 (float x)\fR [inline]\fP, \fR [static]\fP" .PP 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\&. .SS "\fBchaff_eval_t\fP 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)\fR [inline]\fP, \fR [static]\fP" .PP 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\&. .SS "uint32_t chaff_hash2i (int32_t ix, int32_t iy, uint32_t seed)\fR [inline]\fP, \fR [static]\fP" .PP Bit-exact 8-byte XXH32-style hash on full 32-bit integer lattice coordinates (\fRix\fP, \fRiy\fP)\&. Zero 16-bit wrap collision even on Earth-scale (b=23) planets\&. Matches GLSL chaff_hash2i\&. .SS "float chaff_lowpass_f (float wavelength, float step_wu)\fR [inline]\fP, \fR [static]\fP" .PP Continuous C2-quintic Nyquist low-pass transfer weight L(wavelength, step_wu) in [0, 1]\&. .IP "\(bu" 2 step_wu <= 0 -> 1\&.0 (unfiltered point sample) .IP "\(bu" 2 wavelength <= 2*step_wu -> 0\&.0 (sub-Nyquist, skip octave) .IP "\(bu" 2 wavelength >= 4*step_wu -> 1\&.0 (fully resolved) .PP .SS "void chaff_octave_phase (uint8_t shift, float * out_px, float * out_py)\fR [inline]\fP, \fR [static]\fP" .PP Irrational-spaced fractional phase offset per octave in [0, 1)\&. Prevents octave lattice lines from aligning across scales while preserving exact torus wrap\&. .SS "uint32_t chaff_surf_axis_cells (uint32_t period_n, uint8_t period_base_shift, uint8_t shift)\fR [inline]\fP, \fR [static]\fP" .PP Compute exact integer torus cell count for an octave of shift \fRshift\fP\&. Returns 0 for an axis if aperiodic or if cell count overflows int32\&. .SS "void chaff_surf_bounds (const \fBchaff_surf_t\fP * c, float step_wu, float * out_min, float * out_max)\fR [inline]\fP, \fR [static]\fP" .PP O(1) strictly conservative value envelope [out_min, out_max] derived directly from the surface descriptor\&. Guaranteed to contain \fBchaff_surf_eval()\fP for all (wx, wy)\&. .SS "\fBchaff_eval_t\fP chaff_surf_eval_band_split (const \fBchaff_surf_t\fP * 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)\fR [inline]\fP, \fR [static]\fP" .PP Complementary sub-texel band-pass evaluator matching GLSL chaff_eval_surf_band\&. Evaluates strictly the octaves resolved between \fRfine_step_wu\fP and \fRcoarse_step_wu\fP using additive partition-of-unity weight max(0, L(lambda, fine) - L(lambda, coarse))\&. .SH "Author" .PP Generated automatically by Doxygen for chaff from the source code\&.