---
title: "saturate(): IR builder function in typeshade/core/ir"
description: "saturate, an IR builder function in typeshade/core/ir. saturate(x): clamp(x, 0, 1), component-wise, the standard normalized-range clamp for colour channels…"
url: https://typeshade.dev/api/saturate/
language: en
---

# `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()`](https://typeshade.dev/reference/functions/saturate/)

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

## Syntax

```ts
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

```ts
import { fn, saturate, f32T } from 'typeshade/core/ir'

const alpha = fn('alpha', { fade: f32T }, ({ fade }) => saturate(fade))
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| 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. |

## See also

- [`saturate()`](https://typeshade.dev/reference/functions/saturate/)

## Source

[`src/core/ir/node.ts`, line 1367](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/node.ts#L1367), at commit af54ddad5
