Tri-Noise 3D
Triangle-wave 3D noise (WGSL + CPU)
Quick Start
Loading...
Source
Loading...
Documentation
tri-noise-3d
Triangle-wave 3D noise. Produces organic, rippling patterns that look different from Perlin or Simplex noise — more fluid and wave-like.
This module is a WGSL function you embed in your own shader, plus a matching CPU/TypeScript implementation for cases where you need the same values on both sides.
Quick Start
In a shader
Import the WGSL source and prepend it to your shader code:
import { triNoise3DWGSL } from './gpu-modules/tri-noise-3d/tri-noise-3d';
const shaderCode = `
${triNoise3DWGSL}
@fragment
fn main(@location(0) uv: vec2f) -> @location(0) vec4f {
let value = triNoise3D(vec3f(uv * 4.0, 0.0), 0.5, time);
return vec4f(vec3f(value), 1.0);
}
`;
On the CPU
import { triNoise3D } from './gpu-modules/tri-noise-3d/tri-noise-3d';
const value = triNoise3D([x, y, z], 0.5, elapsed);
The CPU implementation produces identical output to the WGSL version.
API
triNoise3DWGSL: string
Raw WGSL source defining three functions: tri, tri3, and triNoise3D. Paste or concatenate this into your shader module.
triNoise3D(position, speed, time): number
CPU implementation. Returns a noise value roughly in [0, 1].
position—[x, y, z]sample pointspeed— Animation rate. Try 0.1–1.0.time— Current time in seconds
How to Modify
- Change the number of octaves: The
forloop runs 4 iterations (i <= 3). Fewer iterations = smoother/cheaper, more = finer detail. - Adjust the frequency scaling:
p = p * 1.2andbp = bp * 1.8control how quickly detail increases per octave. Higher values = more high-frequency detail. - Use as a displacement: Sample
triNoise3Dat vertex positions to displace geometry along normals. - Animate differently: The
speedparameter scales a time offset added uniformly to all axes. For directional animation, modify thevec3f(t * 0.1 * speed)line to weight axes differently.
Further Reading
Rationale
Not all noise needs to be Perlin or Simplex. Triangle-wave noise produces a distinct organic, rippling quality — less "cloudy" than classic gradient noise, more like flowing liquid or heat distortion. It's cheap to compute (no gradient lookups or permutation tables) and works well for animated displacement, water caustics, and abstract procedural textures.
Original Source
- cabbibo/glsl-tri-noise-3d — The original GLSL implementation this module is ported from. Isaac Cohen (cabbibo) is known for creative coding and procedural art. https://github.com/cabbibo/glsl-tri-noise-3d
How It Works
The algorithm composes triangle waves (abs(fract(x) - 0.5)) in 3D across multiple octaves. Each octave:
- Samples a triangle wave of the current position, feeding each axis into the next (creating cross-axis dependency).
- Adds a time-based offset for animation.
- Scales the position up (increasing frequency) and scales the contribution down (decreasing amplitude).
This produces fractal-like detail without any hash tables or gradient vectors — just fract, abs, and arithmetic.
Further Learning
- The Book of Shaders: Noise — Patricio Gonzalez Vivo's chapter on noise covers the design space beyond Perlin/Simplex, including wave-based approaches. https://thebookofshaders.com/11/
- Inigo Quilez: Useful Little Functions — A collection of small mathematical building blocks for procedural graphics, including triangle wave patterns. https://iquilezles.org/articles/functions/