Skip to content
This is the alpha v4 version website. Looking for the v3 documentation?

colorToGLSLString

colorToGLSLString(val): string

Defined in: packages/sigma/src/utils/colors.ts:335

Converts a color string to a GLSL vec4 string representation. The output can be used directly in GLSL shaders.

Parameters

val

string

Color string (hex, rgb, rgba, or HTML color name)

Returns

string

GLSL vec4 string, e.g. “vec4(1.0, 0.0, 0.0, 1.0)” for red

Example

colorToGLSLString("#ff0000") // "vec4(1.0, 0.0, 0.0, 1.0)"
colorToGLSLString("red") // "vec4(1.0, 0.0, 0.0, 1.0)"
colorToGLSLString("rgb(255, 0, 0)") // "vec4(1.0, 0.0, 0.0, 1.0)"
colorToGLSLString("rgba(255, 0, 0, 0.5)") // "vec4(1.0, 0.0, 0.0, 0.5)"