Skip to main content

createColorRampTexture()

function createColorRampTexture(
gl,
colors,
opacity):
| WebGLTexture
| null;

Creates a flexible 1D color-ramp texture supporting either normalized (0–1) or integer (0–255) color definitions.

Parameters

ParameterTypeDescription
glWebGL2RenderingContextThe WebGL2 rendering context.
colorsnumber[][]Array of RGB colors in normalized [0–1] or integer [0–255] format.
opacitynumberOpacity multiplier between 0 and 1.

Returns

| WebGLTexture | null

A WebGLTexture representing the color ramp, or null if creation failed.

Example

const texture = createColorRampTexture(gl, [[1, 0, 0], [0, 0, 1]], 0.8);