Symbols in this topic
srgb
Converts sRGB color literals into linear RGB floats for CPU-side scene constants. Use it when your source color is a web-style hex value or normalized sRGB tuple but your shader math expects linear color.
Import
TypeScript
1
import { srgb } from "vgpu/scene";Signature
TypeScript
1
2
3
4
type SrgbInput = number | string | [number, number, number];
type LinearRgb = [number, number, number];
declare function srgb(input: SrgbInput): LinearRgb;Parameters
| Param | Type | Required | Default | Notes |
|---|---|---|---|---|
| input | number | string | [number, number, number] | ✔ | — | A packed 0xRRGGBB number, a "#rrggbb" hex string, or a three-channel sRGB tuple. Tuple channels are expected in normalized 0..1 units, not byte 0..255 units. |
Returns: LinearRgb ([number, number, number]) — normalized linear RGB channels. Each channel uses the standard sRGB transfer curve: channel / 12.92 for channel <= 0.04045, otherwise ((channel + 0.055) / 1.055) ** 2.4.
Throws: VGPU-CORE-INVALID-USAGE for malformed hex strings; numeric and tuple inputs are not validated.
Examples
TypeScript
1
2
3
4
5
import { srgb } from "vgpu/scene";
const albedo = srgb(0xff8040);
const sky = srgb("#3b82f6");
console.log(albedo.length, sky.length); // 3 3TypeScript
1
2
3
4
5
6
import { srgb } from "vgpu/scene";
const normalizedWhite = srgb([1, 1, 1]);
const normalizedGray = srgb([0.5, 0.5, 0.5]);
void normalizedWhite;
void normalizedGray;Notes
- The numeric form is a packed hexadecimal color (
0xff8040); the string form accepts"#rrggbb"or"rrggbb". Do not callsrgb(255, 128, 64); that is not the function signature. - Tuple input is not clamped. Values outside
0..1,NaN, andInfinityflow through JavaScript arithmetic and can produce non-display color values. srgbis CPU-side only. For texture sampling and post-processing, keep color-management decisions explicit in WGSL.- See also:
degToRad,SceneGeometry.