---
title: "textureSampleLevel(): IR builder in typeshade/core/ir"
description: "textureSampleLevel, an IR builder function in typeshade/core/ir. Sample a 2D texture at an explicit mip level, returning vec4<f32>."
url: https://typeshade.dev/api/texturesamplelevel/
language: en
---

# `textureSampleLevel()`

Function in Builtins

Sample a 2D texture at an explicit mip level, returning `vec4<f32>`.

`import { textureSampleLevel } from 'typeshade/core/ir'`

This export returns an IR node. A `"use typeshade"` file calls the builtin itself: [`textureSampleLevel()`](https://typeshade.dev/reference/functions/textureSampleLevel/)

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

## Syntax

```ts
function textureSampleLevel(
  tex: ReadonlyNode<'texture_2d<f32>'>,
  smp: ReadonlyNode<'sampler'>,
  uv: ReadonlyNode<'vec2<f32>'>,
  level: ReadonlyNode<'f32'> | number,
): Node<'vec4<f32>'>;
function textureSampleLevel(
  tex: ReadonlyNode<'texture_2d_array<f32>'>,
  smp: ReadonlyNode<'sampler'>,
  uv: ReadonlyNode<'vec2<f32>'>,
  layer: ReadonlyNode<'i32' | 'u32'> | number,
  level: ReadonlyNode<'f32'> | number,
): Node<'vec4<f32>'>;
```

## Parameters

**`tex` `ReadonlyNode<'texture_2d<f32>'>`**

**`smp` `ReadonlyNode<'sampler'>`**

**`uv` `ReadonlyNode<'vec2<f32>'>`**

**`level` `ReadonlyNode<'f32'> | number`**

## Return value

`Node<'vec4<f32>'>`

## Description

Sample a 2D texture at an explicit mip level, returning `vec4<f32>`. It needs no derivatives, so it is legal in every stage and is the form a vertex or compute shader uses in place of [`textureSample`](https://typeshade.dev/api/texturesample/), for a displacement map read in a vertex shader, say. A JS number `level` lifts to an `f32` literal. Spelled `textureSampleLevel(t, s, uv, l)` on WGSL and `textureLod(t, uv, l)` on GLSL, where the sampler is part of the texture. The CPU evaluation returns a placeholder under its `gpuStubs` option.

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `textureSampleLevel(tex, smp, uv, level)`. |
| GLSL ES 3.00 (WebGL2) | Supported | `textureLod(tex, uv, level)`. |
| CPU oracle | Stub | The oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with `{ gpuStubs: true }`, which returns a placeholder. |

## In the guide

- [Layouts and resources](https://typeshade.dev/guide/internals/layouts-and-resources/)
- [The CPU oracle](https://typeshade.dev/guide/internals/the-cpu-oracle/)

## See also

- [`textureSampleLevel()`](https://typeshade.dev/reference/functions/textureSampleLevel/)
- [`textureSample`](https://typeshade.dev/api/texturesample/)

## Source

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