saturate()
Function in Builtins
saturate(x): clamp(x, 0, 1), component-wise, the standard normalized-range clamp for colour channels, interpolation factors and coverage.
import { saturate } from 'typeshade/core/ir'
This export returns an IR node. A "use typeshade" file calls the builtin itself: saturate()
The signature, the description and the examples come from the compiler's own source at commit af54ddad5.
Syntax
const saturate: <K extends FloatKey>(x: ReadonlyNode<K>) => Node<K>Parameters
xReadonlyNode<K>
Return value
Node<K>
Description
WGSL has a saturate builtin; GLSL ES
3.00 has none, so the GLSL output is clamp(x, 0.0, 1.0), with the same semantics.
Examples
Example
import { fn, saturate, f32T } from 'typeshade/core/ir'
const alpha = fn('alpha', { fade: f32T }, ({ fade }) => saturate(fade))Targets
| Target | Support | Notes |
|---|---|---|
| WGSL (WebGPU) | Supported |
|
| GLSL ES 3.00 (WebGL2) | Supported |
|
| CPU oracle | Supported | Evaluated in |
See also
Source
src/core/ir/node.ts, line 1367, at commit af54ddad5