hslToRgb

HSL (Hue, Saturation, Lightness) color to RGB.

110 total functionsUpdated: 30/07/2026

hslToRgb

HSL (Hue, Saturation, Lightness) color to RGB.

Parameters

NameTypeDescription
hslvec3<f32>HSL color values (hue: 0-1, saturation: 0-1, lightness: 0-1).

Returns

vec3<f32>color values.

Dependencies

WGSL Code

//! requires hueToRgb
fn hslToRgb(hsl: vec3<f32>) -> vec3<f32> {
  let h = hsl.x;
  let s = hsl.y;
  let l = hsl.z;
  
  if (s == 0.0) {
    return vec3(l); // achromatic
  }
  
  let q = select(l * (1.0 + s), l + s - l * s, l < 0.5);
  let p = 2.0 * l - q;
  
  return vec3(
    hueToRgb(p, q, h + 1.0 / 3.0),
    hueToRgb(p, q, h),
    hueToRgb(p, q, h - 1.0 / 3.0)
  );
}

About wgsl-fns

A JavaScript library providing WGSL utility functions as strings for WebGPU shader development. Includes mathematical utilities, noise generation, signed distance fields, and color manipulation functions.

Install:npm install wgsl-fns
Import:import { hslToRgb, getFns } from 'wgsl-fns'
Usage:getFns(['hslToRgb'])