textureSampleLevel
On this page

textureSampleLevel()

Function in Builtins

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

import { textureSampleLevel } from 'typeshade'

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

Syntax

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, 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

TargetSupportNotes
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

See also

Source

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

Edit this page Report a problem