NAME
ttypt/chaff.h - High-level N-dimensional procedural noise, analytical derivatives, periodic/torus sampling, rotated FBM, and curl-noise flow API.
SYNOPSIS
#include <ttypt/noise.h>
#include <ttypt/chaff_surf.h>
Data Structures
2D divergence-free curl-noise velocity sample (vx, vy).
Macros
Default Q15 octave rotation sine constant (golden-ratio rotation).
Functions
Rotate 2D int16 coordinates in-place using the default Q15 golden-ratio rotation matrix.
Alias of chaff_rotate_q15() for rotating 2D int16 coordinates in-place.
Sample rugged (slope-damped) 2D multi-octave noise with default damping parameters.
Compute default fractal amplitude scaling for octave shift.
Sample a 2D periodic wrapping noise point using default options.
Sample a 2D periodic noise value configured via chaff_periodic_opts_t.
Sample large-scale 2D macro noise at integer coordinates (rx, ry).
Detailed Description
High-level N-dimensional procedural noise, analytical derivatives, periodic/torus sampling, rotated FBM, and curl-noise flow API.
ttypt/chaff.h โ Canonical N-Dimensional Procedural Noise, Lattice Stepper, and Multi-Scale Band-Limited LOD API.
LICENSE: BSD-2-Clause Copyright (c) 2026, tty-pt
Direct include for libchaff. Provides:
- 1.
- Band-limited Nyquist multi-layer region generation (chaff_fill_lod).
- 2.
- Analytical 2D/3D/4D spatial gradients and 2D slice stepping.
- 3.
- Parameterized 2D fixed-point domain rotation (chaff_rot2d_q15).
- 4.
- Generic periodic 2D domain sampling (chaff_wpoint_periodic_2d) and monotonic fractal amplitude scaling (chaff_octave_amplitude_ex).
- 5.
- Optional header-only GPU shader contract via <ttypt/chaff_glsl.h>.
Pure C99, integer-only core, zero floating point, zero game/domain constants.
Macro Definition Documentation
#define CHAFF_DEFAULT_BASE_AMP 1
Default base octave amplitude for fractal amplitude scaling.
#define CHAFF_DEFAULT_MIN_SHIFT 2u
Default minimum octave shift for fractal amplitude scaling.
#define CHAFF_DEFAULT_OUT_SHIFT 4u
Default fractional output shift for Q12.4 rotated FBM accumulators.
#define CHAFF_DEFAULT_PERIOD_SHIFT 16u
Default periodic domain shift (2^16 = 65536 cells).
#define CHAFF_DEFAULT_VSHIFT 8u
Default octave value shift (vshift = 8 yields [0..255] after >> 16).
#define CHAFF_ROT_GOLD_COS_Q15 27874 /***< cos(31.717 deg) * 32768 */
--- Parameterized 2D Fixed-Point Rotation & Anti-Resonance Skew ----------
Function Documentation
void chaff_band_range_for_step_q16 (const chaff_field_t * field, uint8_t min_shift, const int32_t step_q16[], uint8_t * out_lo, uint8_t * out_hi) [inline], [static]
Computes active layer index range [out_lo, out_hi) for a given Q16.16 sampling stride and explicit minimum shift cutoff.
uint32_t chaff_band_weight_q16 (uint8_t shift, int32_t fine_step_q16, int32_t coarse_step_q16) [inline], [static]
Complementary scale-space band-pass weight B(2^shift; fine_step, coarse_step) in Q16 [0..65536]: B(lambda; Delta_fine, Delta_coarse) = L(lambda, Delta_fine) * (1 - L(lambda, Delta_coarse)). Satisfies exact partition of unity: L(lambda, Delta_coarse) + B(lambda; 0, Delta_coarse) == 1.
chaff_coord_t chaff_coord_scale (chaff_coord_t c, int scale_power_of_two) [inline], [static]
Scale fixed-point coordinate: multiplies or divides by 2^scale_power_of_two
void chaff_eval_fade_and_deriv (uint32_t t, uint8_t flags, uint64_t * out_u, uint64_t * out_du) [inline], [static]
Evaluates intra-cell fade u(t) and analytical derivative u'(t) in Q16 based on field->flags:
- CHAFF_FLAG_LINEAR: u(t) = t, u'(t) = 1.0
- CHAFF_FLAG_FADE5: u(t) = t^3(6t^2-15t+10), u'(t) = 30 t^2 (1 - t)^2
- Default / FADE: u(t) = t^2(3 - 2t), u'(t) = 6 t (1 - t)
int32_t chaff_fbm_rotated_2d (const chaff_fbm_opts_t * opts, int32_t x, int32_t y) [inline], [static]
Struct-driven 2D rotated fractal octave accumulator
void chaff_fbm_rotated_2d_4x (const chaff_fbm_opts_t * opts, const int32_t x[4], const int32_t y[4], int32_t out[4]) [inline], [static]
4-wide SIMD struct-driven 2D rotated fractal octave accumulator. Bit-exact with 4 calls to chaff_fbm_rotated_2d(opts, x[i], y[i]).
int32_t chaff_fbm_rotated_2d_ex (int32_t x, int32_t y, uint8_t min_shift, uint8_t max_shift, uint8_t ridged_min_shift, uint8_t amp_min_shift, int16_t base_amp, uint32_t seed, uint32_t seed_salt, int32_t cos_q15, int32_t sin_q15, uint8_t vshift, unsigned fade_flags, uint8_t out_shift) [inline], [static]
Parameterized 2D rotated fractal octave accumulator with configurable vshift, fade_flags, and fixed-point fractional output shift (out_shift = 4 produces Q12.4).
int32_t chaff_fbm_rotated_2d_q12_4 (int32_t x, int32_t y, uint8_t min_shift, uint8_t max_shift, uint8_t ridged_min_shift, uint8_t amp_min_shift, int16_t base_amp, uint32_t seed, uint32_t seed_salt, int32_t cos_q15, int32_t sin_q15) [inline], [static]
Generic 2D rotated fractal octave accumulator in Q12.4 fixed-point. Evaluates octaves from max_shift down to min_shift with C2 quintic fades (NOISE_FADE5), applying ridged multifractal folding on octaves >= ridged_min_shift (pass 255 to disable) and rotating coordinates by (cos_q15, sin_q15) between octaves.
int32_t chaff_fbm_rotated_2d_step_q12_4 (int32_t x, int32_t y, int32_t step_q16, uint8_t min_shift, uint8_t max_shift, uint8_t ridged_min_shift, uint8_t amp_min_shift, int16_t base_amp, uint32_t seed, uint32_t seed_salt, int32_t cos_q15, int32_t sin_q15) [inline], [static]
Scale-filtered 2D rotated fractal octave accumulator in Q12.4 fixed-point with continuous Nyquist step_q16.
void chaff_fbm_rotated_2d_step_q12_4_4x (const int32_t x[4], const int32_t y[4], int32_t step_q16, uint8_t min_shift, uint8_t max_shift, uint8_t ridged_min_shift, uint8_t amp_min_shift, int16_t base_amp, uint32_t seed, uint32_t seed_salt, int32_t cos_q15, int32_t sin_q15, int32_t out[4]) [inline], [static]
4-wide SIMD scale-filtered 2D rotated fractal octave accumulator in Q12.4 fixed-point. Bit-exact with 4 calls to chaff_fbm_rotated_2d_step_q12_4.
void chaff_fill_lod (const chaff_field_t * field, uint8_t min_shift, const chaff_coord_t origin[], const int32_t step_q16[], const uint16_t n[], int32_t * out, size_t stride, unsigned mode) [inline], [static]
Band-limited multi-layer region generator. Automatically filters out octaves whose wavelength shift is below the maximum of:
- 1.
- The explicit min_shift threshold supplied by the caller, and
- 2.
- The continuous Nyquist cutoff shift derived directly from step_q16.
void chaff_fill_slice_3d (const chaff_field_t * field, int16_t z, int16_t origin_x, int16_t origin_y, uint16_t width, uint16_t height, int32_t * out_val, int16_t * out_grad_x, int16_t * out_grad_y) [inline], [static]
Generic bulk 2D slice stepper across a 3D noise field (e.g. z = time). For a fixed Z coordinate across an (X, Y) region:
- Pre-collapses the invariant Z axis once per 3D cell into a 2D quad in registers.
- Evaluates X and Y across the cell using pure integer multiply-adds.
- Produces 100% bit-exact identical values to chaff_sample_grad_3d.
- out_val, out_grad_x, and out_grad_y are optional (can be NULL).
Maximum strip width in pixels buffered on stack during slice evaluation.
void chaff_fill_slice_4d (const chaff_field_t * field, int16_t z, int16_t w, int16_t origin_x, int16_t origin_y, uint16_t width, uint16_t height, int32_t * out_val, int16_t * out_grad_x, int16_t * out_grad_y, int16_t * out_grad_z, int16_t * out_grad_w) [inline], [static]
Generic bulk 2D slice stepper across a 4D noise field (e.g. z = altitude, w = time). For fixed (Z, W) coordinates across an (X, Y) region:
- Pre-collapses the invariant W (16 -> 8) and Z (8 -> 4) axes once per 4D cell into a 2D quad in registers.
- Evaluates X and Y across the cell using pure integer multiply-adds at 2D cost.
- Produces 100% bit-exact identical values and 4D gradients to chaff_sample_grad_4d.
- out_val and out_grad_* are optional (can be NULL).
void chaff_grad_noise2d_4x (const chaff_field_t * field, const int16_t wx[4], const int16_t wy[4], chaff_sample_2d_t out[4]) [inline], [static]
4-wide batch 2D analytical gradient noise evaluator. Reuses cached 2D lattice corners across lanes sharing a cell (with SIMD 4-corner hash on miss). Bit-exact with 4 calls to chaff_sample_grad_2d(field, wx[i], wy[i]).
uint32_t chaff_lerp (uint32_t v0, uint32_t v1, uint32_t f, unsigned x) [inline], [static]
Exact fixed-point linear interpolation: v0 + (((v1 - v0) * f) >> x)
uint8_t chaff_nyquist_shift_q16 (const int32_t step_q16[], uint8_t dim) [inline], [static]
Derives the Nyquist minimum wavelength shift directly from a Q16.16 sampling stride. By the Nyquist-Shannon sampling theorem, an octave with wavelength 2^shift requires a sampling period Delta <= 2^(shift - 1), so min_shift = floor(log2(2 * max_step)).
int16_t chaff_octave_amplitude_ex (uint8_t shift, uint8_t min_shift, int16_t base_amp) [inline], [static]
Parameterized 1/f continuous fractal amplitude scaling (zero switch-ladders): Higher shifts (longer wavelengths) strictly produce higher amplitudes: A(s) = base_amp * 2^((s - min_shift) / 2) using exact integer half-octave steps (1, 1.5, 2, 3, 4, 6, 8, ...).
uint32_t chaff_octave_weight_q16 (uint8_t shift, int32_t step_q16) [inline], [static]
Continuous C2 Nyquist low-pass weight L(2^shift, Delta) in Q16 [0..65536] for dyadic octave shift.
void chaff_rot2d_i32_q15 (int32_t * x, int32_t * y, int32_t cos_q15, int32_t sin_q15) [inline], [static]
Parameterized 2D fixed-point Q15 rotation for int32_t coordinates
void chaff_rot2d_i32_q15_4x (int32_t x[4], int32_t y[4], int32_t cos_q15, int32_t sin_q15) [inline], [static]
4-wide SIMD parameterized 2D fixed-point Q15 rotation for int32_t coordinates. Bit-exact with 4 calls to chaff_rot2d_i32_q15.
void chaff_rot2d_q15 (int16_t * x, int16_t * y, int32_t cos_q15, int32_t sin_q15) [inline], [static]
Parameterized 2D fixed-point Q15 rotation for int16_t coordinates
chaff_flow_2d_t chaff_sample_flow_2d (const chaff_field_t * psi_field, const chaff_flow_desc_t * desc, int16_t x, int16_t y, int16_t t) [inline], [static]
Evaluates a divergence-free 2D curl-flow vector field from a 3D streamfunction field Psi(x, y, t): v = v_base + curl(Psi) = (base_vx + dPsi/dy, base_vy - dPsi/dx). Because div(curl(Psi)) = d^2Psi/dxdy - d^2Psi/dydx = 0 identically, the resulting velocity field is guaranteed divergence-free for any streamfunction Psi.
chaff_sample_2d_t chaff_sample_grad_2d (const chaff_field_t * field, int16_t wx, int16_t wy) [inline], [static]
Computes value and analytical surface normal slopes in a single pass. Evaluates the exact derivative of the configured fade curve. Costs zero additional corner hashes compared to standard evaluation.
chaff_sample_3d_t chaff_sample_grad_3d (const chaff_field_t * field, int16_t x, int16_t y, int16_t z) [inline], [static]
Generic 3D point query with analytical spatial gradient. Evaluates value N(x, y, z) and continuous spatial gradient (dN/dx, dN/dy, dN/dz) in a single 8-corner pass using the analytical fade derivative. Costs 8 corner hashes instead of 24 hashes from finite differences (3x speedup).
chaff_sample_4d_t chaff_sample_grad_4d (const chaff_field_t * field, int16_t x, int16_t y, int16_t z, int16_t w) [inline], [static]
Generic 4D point query with analytical spatio-temporal gradient. Evaluates value N(x, y, z, w) and continuous 4D gradient (dN/dx, dN/dy, dN/dz, dN/dw) in a single 16-corner pass using the analytical fade derivative. Costs 16 corner hashes instead of 64 hashes from finite differences (4x speedup).
uint32_t chaff_sample_periodic_2d (int32_t rx, int32_t ry, uint8_t shift, uint8_t period_shift, uint8_t vshift, uint32_t seed) [inline], [static]
Parameterized periodic 2D domain sampler with explicit period_shift and vshift. Clamps shift to period_shift - 1 so at least 2 lattice cells span the period.
chaff_sample_2d_t chaff_sample_rugged_2d_ex (const chaff_field_t * field, int16_t wx, int16_t wy, int32_t cos_q15, int32_t sin_q15) [inline], [static]
Parameterized rugged point evaluation: rotates octave coordinate systems by (cos_q15, sin_q15) per octave to break power-of-two Cartesian lattice resonance, and inverse-rotates the analytical gradients back into world space via the chain rule (R^l)^T.
uint32_t chaff_sample_torus_macro (int32_t rx, int32_t ry, uint8_t shift, uint32_t seed) [inline], [static]
Convenience wrapper for 16-bit periodic 2D domain (period = 2^16, vshift = 8)
uint32_t chaff_wavelength_weight_q16 (int32_t wavelength_q16, int32_t step_q16) [inline], [static]
Continuous C2 Nyquist low-pass transfer function L(lambda, Delta) in Q16 [0..65536]:
- For step_q16 <= 0 (point sample): returns 65536 (1.0).
- For wavelength <= 2 * step_q16 (sub-Nyquist): returns 0 (skip evaluation).
- For wavelength >= 4 * step_q16 (fully resolved): returns 65536 (1.0).
- For 2 * step_q16 < wavelength < 4 * step_q16: smooth C2 quintic transition.
void chaff_wpoint_periodic_2d_4x (const int32_t x[4], const int32_t y[4], uint8_t shift, uint8_t period_shift, uint8_t vshift, uint32_t seed, uint32_t out[4]) [inline], [static]
4-wide SIMD continuous 2D periodic octave sampler (NOISE_FADE5). Bit-exact with 4 calls to chaff_wpoint_periodic_2d(x[i], y[i], ...).
uint32_t chaff_wpoint_periodic_2d_ex (int32_t x, int32_t y, uint8_t shift, uint8_t period_shift, uint8_t vshift, uint32_t seed, unsigned fade_flags) [inline], [static]
Evaluates a continuous 2D periodic octave with domain period 2^period_shift and feature cell wavelength 2^shift (where shift <= period_shift).
Author
Generated automatically by Doxygen for chaff from the source code.