int
Explicitly converts any numerical input into an integer (int) by truncating the decimal part. It is essential for operations requiring whole numbers (like loops, array indexing) and ensuring type safety.
Core Advantages
Guarantees type safety for shader functions that strictly require integer inputs (e.g., loop counters, `texelFetch`), preventing compilation errors. It clarifies the developer's intent and converts continuous float values (like time) into discrete integer steps for creating specific effects.
Common Uses
Defining integer counters for loops (Loop Node)
Providing integer coordinates for data texture lookups (texelFetch)
Creating stepped or quantized animations from continuous values like time
Indexing elements in arrays or Storage Buffers
How to adjust
It transforms smooth, continuous inputs into discrete, stepped outputs. For example, applying `int()` to a smooth gradient controlled by UV coordinates will turn it into a series of hard-edged color bands (a mosaic effect). Applying it to a value that smoothly animates an object's position will cause the object to 'tick' or 'jump' to new positions instead of moving fluidly.
Code Examples
1// Convert continuous time into an integer to create a stepped effect
2const steppedTime = int( timerLocal() );
3
4// The value of steppedTime will jump every second: 0, 1, 2, 3...