uvec3
Converts data like 3D float vectors, other vectors, or single numbers into a vector of three unsigned integers (uvec3). The conversion is done by truncating fractional parts, serving as a key bridge from continuous 3D space to discrete voxel grids, often used to get 3D grid indices.
Core Advantages
Implements voxel or 3D grid logic. By converting continuous world coordinates into discrete uvec3 integer indices, it can determine the 3D cell a point belongs to in space, which is fundamental for advanced visual effects like voxel terrain, 3D cellular automata, or volumetric clouds.
Common Uses
Procedural voxel world generation
Volumetric lighting or fog effects
3D data visualization
How to adjust
The output of uvec3 is determined by its input values, with the core behaviors being truncation of decimals (not rounding) and unsigned conversion (negative inputs typically become 0). For example, uvec3(9.9, -2.5, 1.1) results in uvec3(9, 0, 1). Its constructor is flexible, allowing combinations of different types, such as uvec3(myVec2, myFloat).
Code Examples
1// Convert continuous world coordinates (vec3) to a discrete voxel index
2// e.g., vec3(4.8, 1.1, 2.7) -> uvec3(4, 1, 2)
3const voxelIndex = uvec3( positionWorld );