@tty-pt/chaff logo

@tty-pt/chaff

npm version License: BSD-2-Clause TypeScript Ready Node.js Native WebAssembly Zero Floats

Universal Node.js and Browser bindings for libchaff, the pure-integer N-dimensional procedural noise engine with $C^2$ Hermite smoothstep interpolation, continuous multi-scale surface cascades, periodic domain wrapping, analytical gradients, and hypercube matrix stepping. Canonical C headers: <ttypt/chaff.h>, <ttypt/chaff_surf.h>, <ttypt/noise.h>, and <ttypt/chaff_glsl.h>.

๐Ÿ“– Full C & Mathematical Documentation: See the main libchaff GitHub README for the mathematical foundations of recursive noise, forward-difference matrix stepping, analytical surface normals, and GLSL ES 3.0 shader parity.


1. Overview & Domain Concepts

libchaff (@tty-pt/chaff) is an ultra-fast, deterministic procedural noise engine engineered for continuous planetary terrain, bathymetry, and 4D spatiotemporal atmospheric fields:

  1. Bit-Exact Pure Integer Core (Zero Floats):
  1. $C^2$ Quintic Hermite Smoothstep Interpolation:
  1. Hypercube Forward-Difference Matrix Stepping (chaffOctaves / noiseOctaves):
  1. Analytical Gradients, 4-Wide SIMD 2D Batching, Thread-Local Cell Caching & Anti-Resonance FBM (C / WASM):

2. Installation

npm config set @tty-pt:registry https://tty.pt/npm/
npm install @tty-pt/chaff

Native OS & Mobile Packages (tty.pt): Prebuilt native C packages (libchaff) for Linux (apt, apk, pacman, dnf), macOS (brew), Windows (winget, MSYS2), and OpenBSD (pkg_add), plus static mobile sysroots for Android (https://tty.pt/android/) and iOS (https://tty.pt/ios/ โ€” libchaff.xcframework) are available via the tty.pt package repositories.


3. Quickstart

import {
  chaffPoint1D,
  chaffPoint2D,
  chaffPoint3D,
  chaffPoint4D,
  chaffPointN,
  chaffOctaves
} from "@tty-pt/chaff";

const seed = 0x1337BEEF;

// 1. Continuous 1D / 2D / 3D / 4D point queries (shift = log2 lattice spacing)
const h1 = chaffPoint1D(128, seed, 4);
const h2 = chaffPoint2D(1024, -2048, seed, 6);
const h3 = chaffPoint3D(100, 200, 42 /* time Z */, seed, 5);
const h4 = chaffPoint4D(100, 200, 30, 15 /* time W */, seed, 5);
console.log({ h1, h2, h3, h4 });

// 2. Arbitrary N-dimensional point query
const hn = chaffPointN([12, 34, 56, 78, 90], seed, 4);

// 3. Multi-octave 2D chunk synthesis via forward-difference matrix stepping
//    cy = 5 -> (2^5 x 2^5) = 32x32 = 1024 cells
const heightmap = chaffOctaves(
  2,                // 2D field
  [0, 0],           // chunk origin [x0, y0]
  [
    { x: 5, w: 64 }, // Macro octave: frequency shift 5, weight 64
    { x: 3, w: 24 }, // Meso octave:  frequency shift 3, weight 24
    { x: 1, w: 8 }   // Micro octave: frequency shift 1, weight 8
  ],
  seed,
  5                 // log2 chunk dimension (2^5 = 32)
);
console.log("Generated cells:", heightmap.length, "Origin sample:", heightmap[0]);

4. JavaScript / TypeScript API Reference

Point Queries

Bulk Multi-Octave Matrix Synthesis

WebAssembly Reactor Access


5. C Development Headers & Native Integration

CFLAGS += -I./node_modules/@tty-pt/chaff/include
LDLIBS += -lchaff -lxxhash

License

BSD-2-Clause โ€” Copyright (c) 2026, Paulo Quirino <quirinpa@gmail.com>. See LICENSE.

Documentation