convert
A universal type conversion function that safely converts a node's data to a specified target type, such as from a `vec3` to a `float`, or from a `float` to a `vec3`.
Core Advantages
It simplifies tedious data splitting/recombination tasks (like extracting luminance from a color with multiple nodes) into a single step. It explicitly states the intent of type conversion, improving code readability and type safety, thus preventing compilation errors from type mismatches.
Common Uses
Create a grayscale color from a single value: `convert(myFloat, 'vec3')`
Extract a single channel/luminance from a color: `convert(myColor, 'float')`
Visualize data for debugging: `convert(uv(), 'vec3')` to view UV coordinates
Adapt function parameters: `convert(myVec4, 'vec3')` to match functions like `dot()`
How to adjust
By changing its target type parameter (e.g., from 'float' to 'vec3'), you completely alter how the data is interpreted by downstream nodes. For instance, converting `uv()` to 'float' yields a horizontal gradient, while converting it to 'vec3' produces a 2D red-green debug map. It determines the data's dimension and structure, fundamentally changing the visual output.
Code Examples
1// Convert a float value (wave) oscillating between [-1, 1] to a grayscale color
2// wave: 0.5 -> vec3(0.5, 0.5, 0.5)
3const grayPulse = convert( wave, 'vec3' );
4
5// Offset a base blue color with this pulsing gray to create a "breathing" effect
6const finalColor = baseBlueColor.add( grayPulse );