log2
Calculates the base-2 logarithm (log₂(x)), a core tool for handling graphics tasks related to powers of two, such as Mipmap levels and bit depth.
Core Advantages
Its core advantage is directly answering '2 to what power equals the input?', converting exponential power-of-two relationships (like texture sizes) into linear values (like Mipmap levels) with clarity and efficiency.
Common Uses
Calculating and visualizing Mipmap levels
Processing bit-related data
Procedurally generating 'tree-ring' or 'stepped' patterns
How to adjust
The effect is driven by the input `x`; every time `x` doubles, the result of `log2(x)` increases by 1. When creating patterns, a multiplier is often used to scale the input (e.g., `log2(distance * scale)`). Increasing the `scale` makes the pattern (like rings) denser, as the input value doubles more quickly.
Code Examples
1// Create 'tree-ring' patterns with exponentially increasing spacing
2const rings = fract( log2( distance * 16.0 ) );