saturate
On this page

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'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

const saturate: <K extends FloatKey>(x: ReadonlyNode<K>) => Node<K>

Parameters

x ReadonlyNode<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'
const alpha = fn('alpha', { fade: f32T }, ({ fade }) => saturate(fade))

Targets

TargetSupportNotes
WGSL (WebGPU) Supported

saturate(x).

GLSL ES 3.00 (WebGL2) Supported

clamp(x, 0.0, 1.0).

CPU oracle Supported

Evaluated in f64 by the oracle.

Source

src/core/ir/node.ts, line 1596, at commit 26de7be8

Edit this page Report a problem