rand
A deterministic pseudo-random number generator used in shaders to create procedural details like noise and grain without texture maps.
Core Advantages
Procedurally adds rich visual details (like grain, speckles, or patterns) to materials, reducing reliance on texture files and saving memory and network requests.
Common Uses
Simulating film grain or noise
Procedurally generating starry skies or raindrops
Adding irregularity to procedural textures like wood or marble
Smoothing color gradients using dithering
How to adjust
The core adjustment method is manipulating the input UV coordinates. Multiply by a factor (e.g., `uv().mul(10)`) to change the pattern's size and density; add a time-varying value (e.g., `uv().add(timer())`) to animate the static noise; process its output with functions like `step()` or `floor()` to convert smooth grayscale noise into high-contrast patterns.
Code Examples
1// Turn grayscale noise into high-contrast black and white dots
2const highContrastNoise = step( 0.5, rand( uv().mul( 20 ) ) );