bitXor
Performs a bitwise XOR (^) operation, primarily used to efficiently toggle a state flag or to generate procedural patterns.
Core Advantages
Provides a single, branchless instruction to toggle a state (on to off, off to on), which is far more efficient and concise than using conditional logic. Its reversible nature is also useful for simple encoding and non-destructive drawing.
Common Uses
Toggling interactive states (e.g., selection highlights).
Generating procedural patterns like checkerboards.
Simple, reversible data encoding/obfuscation with a key.
Implementing non-destructive XOR drawing for temporary overlays.
How to adjust
Its effect can be adjusted in two main ways: 1) As a logic switch: repeatedly XORing a state integer with a constant mask will toggle that state on and off. 2) As a pattern generator: changing the integer inputs (e.g., by scaling UVs differently or adding time) will directly alter the resulting visual pattern, creating effects from stable checkerboards to dynamic noise.
Code Examples
1// Generate a checkerboard pattern from UVs
2const x = floor( uv().x.mul( 16.0 ) ).to_int();
3const y = floor( uv().y.mul( 16.0 ) ).to_int();
4
5// The lowest bit of the XOR result creates the pattern
6const pattern = bitAnd( bitXor( x, y ), 1 );
7
8material.colorNode = vec3( pattern );