color
A factory function that creates a color node (`ColorNode`) in TSL. It converts various color formats (like hexadecimal numbers) into a `vec3` or `vec4` color vector usable in the shader.
Core Advantages
Provides a unified, convenient, and type-safe way to introduce colors into the shader graph. It automatically converts user-friendly color representations (e.g., `0xff0000`) into the `vec3(1.0, 0.0, 0.0)` required by GLSL, greatly simplifying color definition.
Common Uses
Defining a static base color for a material.
Creating color constants for use by other nodes (like `mix` or math operations).
Wrapping a `THREE.Color` object from JavaScript to create a dynamically updatable uniform color node.
Defining the color values to be returned under different conditions in `cond` or `switch` logic.
How to adjust
Adjust by changing the parameter passed to the `color()` function. You can directly modify the hexadecimal value (e.g., from `color(0xff0000)` to `color(0x00ff00)`). If a `THREE.Color` object is passed, you can modify that object's color in JavaScript, and the effect will be automatically synchronized to all materials using this node.
Code Examples
1// Create two color nodes using hexadecimal numbers
2const primaryColor = color( 0xff0000 ); // Red
3const secondaryColor = color( 0x0000ff ); // Blue
4
5// Mix between the two colors
6const mixedColor = mix( primaryColor, secondaryColor, myFactor );