Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit6fcc6699f3

README.md

periodic_noise

Value noise and fBm that repeat along x, for a pattern laid around a circle: a sky drawn over the azimuth, a ring, a band that closes on itself. A pattern whose x runs over one whole period as the angle runs once around meets itself where the angle wraps, so the circle closes with no seam.

  • zero_azimuth(dir): the azimuth of dir about +Y as a fraction of a turn, 0 and 1 along -X, 0.5 along +X.
  • zero_periodic_noise(p, period): smooth value noise in [0, 1] over a lattice that repeats every period cells along x.
  • zero_periodic_fbm(p, period, octaves, lacunarity): the fractal sum of octaves layers of that noise, each at half the amplitude of the one before and close to lacunarity times its frequency: each layer takes the frequency that fits a whole number of its cells in period, so the sum repeats every period too.
  • zero_wrap_cell(cell, period): a whole-numbered cell wrapped into [0, period), for a lattice of its own (a star field over the azimuth) that closes the same way.
  • zero_hash21(p): the lattice hash the noise is built on, to [0, 1).

A period is a whole number of cells. An offset added to p, an animation's drift or a domain warp's displacement included, keeps the period.

#include "@builtin::shaderModules.periodic_noise"

// 5 cells once around the horizon, 2 from zenith to nadir.
let p = vec2<f32>(zero_azimuth(dir) * 5.0, acos(dir.y) / 3.14159265 * 2.0);
let v = zero_periodic_fbm(p + offset, 5.0, 5, 2.1);

// A star field of cells about as wide as 1/350 of a radian, closing at -X.
let cells_around = 2199.0;
let star_cell = vec2<f32>(
    zero_wrap_cell(floor(zero_azimuth(dir) * cells_around), cells_around),
    floor(acos(dir.y) * 350.0));
let star = step(0.993, zero_hash21(star_cell));

The aurora_sky and fluid_sky shaders draw their domain-warped skies with it.

Pure math: no bindings, no uniforms.