color.map.fromPalette¶
Summary¶
color.map.fromPalette creates a map with one texel per color. Use the default nearest filter for categorical colors.
Syntax¶
fromPalette(colors: ReadonlyArray<Color4>, desc?: ColormapDescriptor): Colormap
const map = WasmGPU.color.map.fromPalette(colors);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
colors |
ReadonlyArray<Color4> |
Yes | From 1 through 8192 RGBA tuples. Channels must be finite and are clamped to [0, 1]. |
desc |
ColormapDescriptor |
No | colorSpace defaults to "srgb" and filter to "nearest". Use colorSpace: "linear" for colors produced by color.parse or color.palette.swatch. |
Returns¶
Colormap - Map with width equal to the number of colors. Both CPU and GPU can sample it. It is also available as Colormap.fromPalette.
Notes¶
The palette uses one lookup entry per input, so resolution and interpolation do not affect it. Setting filter: "linear" blends adjacent texels at lookup time.
Example¶
const map = WasmGPU.color.map.fromPalette([[0.1, 0.2, 0.8, 1], [0.9, 0.9, 0.2, 1]]);
console.log(map.sampleCPU(0.75));