floatBitsToUint
Bitcasts a float or float vector to an unsigned integer type of the same width; no bits change, only the interpretation.
Core Advantages
Lossless bit-level access to floats, enabling bitwise ops, packing/unpacking, hashing, and GPGPU interop.
Common Uses
Apply bit masks, shifts, and bit counts to values produced as floats
Pair with uintBitsToFloat for packing/unpacking
Derive stable unsigned seeds from continuous noise/random values
Write float results into uint-based textures/buffers (same bit width)
How to adjust
Input must be float or vecN; output is uint or uvecN. To test a specific bit, build a mask with shiftLeft: bitAnd( floatBitsToUint(x), shiftLeft( uint(1), n ) ).greaterThan(0). Cast to float and normalize if you need visualization. Note: unlike numeric cast uint(x), this is a bit reinterpretation.
Code Examples
1// Generate a [0,1] wave from UV
2const v = sin( uv().x.mul( 32.0 ) ).mul( 0.5 ).add( 0.5 );
3
4// Bitcast to uint (no numeric conversion)
5const bits = floatBitsToUint( v );
6
7// Use the least significant bit for a black/white stripe
8const mask = bitAnd( bits, uint( 1 ) ).greaterThan( 0 );
9
10// Apply to color
11material.colorNode = cond( mask, color( 'white' ), color( 'black' ) );