---
title: "textureSampleLevel / textureLod: shader function guide"
description: "Explicit-level sampling filters a texture at a mip level chosen by the caller. Use it for compute-shader texture reads or deliberate control of image detail."
url: https://typeshade.dev/reference/functions/textureSampleLevel/
language: en
---

# `textureSampleLevel`

Function

Explicit-level sampling filters a texture at a mip level chosen by the caller.

**Related names in other languages**

These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.

- GLSL: `textureLod`

[Targets](https://typeshade.dev/reference/functions/textureSampleLevel/#targets)

## Compare examples

Compare base-mip sampling with the averaged mip. The coordinate stays fixed while detail changes.

**Model assumptions**`uv = vec2(0.25, 0.25); filter = linear; mip = nearest; levels = [2 × 2, 1 × 1]`

**Example 1`level = 0`**

`0.75` `1` `0` `0.25`

Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.

**Result**

`0`

**Example 2`level = 1`**

`0.5`

Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.

**Result**

`0.5`

**Example 3`level = 0; uv = vec2(0.75, 0.75)`**

`0.75` `1` `0` `0.25`

Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.

**Result**

`1`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it for compute-shader texture reads or deliberate control of image detail.

## Inputs and limits

The model contains a base grid and its averaged mip. Actual interpolation between mip levels depends on the sampler. Use a texture with the required mip chain.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`textureSample`](https://typeshade.dev/reference/functions/textureSample/)
- [`textureLoad`](https://typeshade.dev/reference/functions/textureLoad/)
- [`textureSampleBias`](https://typeshade.dev/reference/functions/textureSampleBias/)
- [`textureSampleGrad`](https://typeshade.dev/reference/functions/textureSampleGrad/)
- [`textureGather`](https://typeshade.dev/reference/functions/textureGather/)

**WGSL**

`textureSampleLevel(a, b, c, d)`

**GLSL ES 3.00**

`textureLod(a, c, d)`

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Samples a float texture through the sampler `smp` at an explicit mip `level`, in any stage; the coordinate is a `vec2` on a `texture_2d` and a `vec3` on a `texture_cube` or a `texture_3d`.

## Syntax

```ts
declare function textureSampleLevel(
  tex: texture_2d<f32>,
  smp: sampler,
  uv: vec2,
  level: number,
): vec4
declare function textureSampleLevel(
  tex: texture_2d_array<f32>,
  smp: sampler,
  uv: vec2,
  layer: number,
  level: number,
): vec4
declare function textureSampleLevel(
  tex: texture_cube<f32>,
  smp: sampler,
  dir: vec3,
  level: number,
): vec4
declare function textureSampleLevel(
  tex: texture_3d<f32>,
  smp: sampler,
  coord: vec3,
  level: number,
): vec4
declare function textureSampleLevel(tex: texture_1d<f32>, smp: sampler, coord: number, level: number): vec4
declare function textureSampleLevel(
  tex: texture_cube_array<f32>,
  smp: sampler,
  dir: vec3,
  layer: number,
  level: number,
): vec4
```

A `number` in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

`type f32 = number & { readonly [f32Tag]?: true }`

A `number` you write as a type is inferred from its uses, and `f32`, `i32` and `u32` fix a width; [the TypeScript constructs page](https://typeshade.dev/guide/language/from-typescript/) carries that row with the compiler's emit.

## Parameters

- `tex` `texture_2d<f32>``texture_2d_array<f32>``texture_cube<f32>``texture_3d<f32>``texture_1d<f32>``texture_cube_array<f32>`
- `smp` `sampler`
- `uv` optional `vec2`
- `dir` optional `vec3`
- `coord` optional `vec3``number`
- `level` `number`
- `layer` optional `number`

## Return value

`vec4`

## Description

On a `texture_2d_array` the layer comes before the level. Compiles to `textureSampleLevel` on WGSL and `textureLod` on GLSL.

The CPU oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with `{ gpuStubs: true }`, which returns a placeholder.

## Targets

**WGSL**

`textureSampleLevel(a, b, c, d)`

**GLSL ES 3.00**

`textureLod(a, c, d)`

## Examples

- [`gallery/cube-array-gather/cube-array-gather.shade.ts`](https://typeshade.dev/guide/examples/cube-array-gather/)
- [`gallery/cube-env/cube-env.shade.ts`](https://typeshade.dev/guide/examples/cube-env/)
- [`gallery/separable-blur/separable-blur.shade.ts`](https://typeshade.dev/guide/examples/separable-blur/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#textures)
- [`textureSampleLevel()` in `typeshade/core/ir`](https://typeshade.dev/api/texturesamplelevel/)
