Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

fx_noise

Procedural noise for effect shaders — the integer hashes underneath it, value and gradient noise in 2D and 3D, fBm over either, curl noise, and worley/voronoi carrying a distance and a cell id.

#include "@builtin::deprecated.deprecatedParticles.fx.fx_noise"

Pure math — no bindings. A Surface-domain shader and a .computeShader see different generated frameworks and can share a function only when it touches neither, so a plume's material and the compute pass that simulates it read one field rather than two that drift apart.

Every generator takes an explicit seed as its last argument, so one shader draws several uncorrelated fields from the same coordinates.

Hashes

fx_hash_u32, fx_hash_u2, fx_hash_u3 mix 32-bit words; fx_unorm and fx_snorm turn a word into a float in [0,1) or [-1,1). fx_hash11, fx_hash21, fx_hash31, fx_hash22 and fx_hash33 take floats and hash the bits fx_bits reads off them, which folds -0.0 onto 0.0 so both spellings of the number reach the same word.

The mixing is integer, which is what makes a value the same bit pattern wherever the shader runs — the same on native and on the web.

Noise

FunctionRangeProperty it guarantees
fx_value_noise2(p, seed)[0,1)at an integer p the value is fx_lattice21(p, seed) exactly
fx_value_noise3(p, seed)[0,1)at an integer p the value is fx_lattice31(p, seed) exactly
fx_gradient_noise2(p, seed)[-1,1]exactly 0 at every integer p
fx_gradient_noise3(p, seed)[-1,1]exactly 0 at every integer p

fx_lattice21 / fx_lattice31 read a corner's value directly, and fx_gradient2 / fx_gradient3 read the unit gradient a corner carries. fx_fade is the quintic both interpolate across a cell with.

fBm

fx_fbm2(p, octaves, lacunarity, gain, seed) and fx_fbm3(...) sum octaves of gradient noise, each lacunarity times the frequency of the one before it and its amplitude scaled by gain, divided by the amplitudes summed — so the range stays [-1,1] for any gain, and one octave returns that octave exactly. fx_ridged_fbm3 folds each octave about zero so the field's peaks are creases.

gain is read as a magnitude — how fast the amplitudes fall away, which is a size rather than a direction. That is what keeps the sum of amplitudes a positive number the total is divided by, and so keeps every range above true whatever the caller passes.

octaves is held to FX_FBM_MAX_OCTAVES (12), which is the loop the shader compiles.

Curl noise

fx_curl_noise3(p, seed) is the curl of fx_curl_potential3, taken over the step FX_CURL_EPSILON. A vector field built as a curl is divergence-free: a particle advecting along it is neither piled up nor torn away from its neighbours.

Worley / voronoi

fx_worley2(p, seed) and fx_worley3(p, seed) return dist, the cell that owns the nearest feature point, and a stable id in [0,1) for that cell — the value a caller tints a voronoi region by. fx_cell_point2 / fx_cell_point3 give where inside its own cell a cell's feature point sits, so a caller can place a sample exactly on one; fx_cell_id2 / fx_cell_id3 give the id directly. fx_worley_fbm2 sums inverted octaves of the distance.