trunc
Truncates one or more floating-point numbers towards zero by discarding their fractional parts, returning their integer components (e.g., 3.7 becomes 3, -2.8 becomes -2).
Core Advantages
Provides a highly efficient method on the GPU to discretize continuous values (like UV coordinates or time), serving as a fundamental tool for creating pixelated, mosaic, or stepped effects.
Common Uses
Creating pixelation or mosaic texture effects
Generating procedural grids or checkerboard patterns
Converting smooth animations into stepped, frame-by-frame animations
How to adjust
The granularity of the effect is controlled by multiplying the input value *before* it enters the `trunc` node. A larger multiplier results in a denser, finer grid (more pixel blocks), while a smaller multiplier creates a coarser, larger grid.
Code Examples
1// Define the density of the pixelation grid
2const density = 10;
3
4// Scale up the UVs, truncate the decimals, then scale back down.
5// This converts continuous UV coordinates into a 10x10 grid.
6const pixelatedUV = trunc(uv().mul(density)).div(density);