cos
A math node that wraps the GLSL `cos()` function. It takes an input (typically time or UV coordinates) and outputs a periodic value that smoothly oscillates between -1 and 1.
Core Advantages
Greatly simplifies the creation of periodic dynamic effects like waves and pulses by abstracting the low-level `cos()` function into a reusable node. It enhances code readability and composability, allowing developers to think in a more intuitive, node-based way without manually writing GLSL and managing variables.
Common Uses
Simulating water or flag wave effects by modifying vertex height in the vertex shader.
Creating smooth breathing light or pulsing effects by periodically changing a material's emissive color intensity.
Generating procedural stripes or circular ripple patterns in the fragment shader based on UV coordinates.
Serving as a 'ping-pong' mix factor that oscillates between 0 and 1, used for smooth transitions between two states (e.g., colors, textures).
How to adjust
Adjust the effect by controlling its input. Multiplying the input by a value (frequency) before the `cos` node makes the oscillation denser or sparser; adding a value (phase, often time) shifts or animates the effect.
Code Examples
1 // Create a value that smoothly oscillates between 0.0 and 1.0
2 const pulse = cos( time ).mul( 0.5 ).add( 0.5 );
3
4 // Use it to drive the intensity of an emissive color
5 material.emissiveColor = baseColor.mul( pulse );