sign
Extracts the sign of one or more numeric values (positive, negative, or zero), converting them to 1.0, -1.0, or 0.0, respectively, to determine their 'direction' while ignoring their 'magnitude'.
Core Advantages
Provides a high-performance, branchless way to perform conditional logic on the GPU, avoiding the potential performance costs associated with traditional if-else statements.
Common Uses
Determining if a point is inside or outside an object in SDFs
Creating hard-edged toon shading
Generating symmetrical or mirrored procedural patterns
How to adjust
Adjusting its input node does not produce smooth gradients but instead moves the 'mutation' boundary where the value is 0. This sharply alters the pattern's geometric shape, making it ideal for creating visuals with hard edges and strong contrast.
Code Examples
1// Center the UV coordinates to the [-0.5, 0.5] range
2const centeredUV = uv().sub( 0.5 );
3
4// Get the sign of each component, resulting in (-1,-1), (1,-1), (-1,1), or (1,1)
5const signNode = sign( centeredUV );