textureSample
On this page

textureSample

Function

Samples a float texture through the sampler smp with the implicit level of detail, in the fragment stage only: at uv on a texture_2d, by a vec3 direction on a texture_cube, by a vec3 coordinate on a texture_3d, by one f32 on a texture_1d, and on an array texture the argument after the coordinate picks the layer.

The signature and the sentence under each name are the compiler's own text at commit 26de7be8.

Syntax

declare function textureSample(tex: texture_2d<f32>, smp: sampler, uv: vec2): vec4
declare function textureSample(
tex: texture_2d_array<f32>,
smp: sampler,
uv: vec2,
layer: number,
): vec4
declare function textureSample(tex: texture_cube<f32>, smp: sampler, dir: vec3): vec4
declare function textureSample(tex: texture_3d<f32>, smp: sampler, coord: vec3): vec4
declare function textureSample(tex: texture_1d<f32>, smp: sampler, coord: number): vec4
declare function textureSample(
tex: texture_cube_array<f32>,
smp: sampler,
dir: vec3,
layer: 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 declaration you write still needs a width, and a bare number on a field or a parameter is refused; the TypeScript constructs page carries that row with the compiler's own message.

Parameters

Return value

vec4

Description

Compiles to textureSample on WGSL and texture on GLSL, where the layer is folded into a vec3 coordinate; a texture_1d or a texture_cube_array has no GLSL ES 3.00 form, so a module using one emits WGSL alone.

Targets

WGSL
textureSample(a, b, c)
GLSL ES 3.00
texture(a, c)

Examples

See also

Edit this page Report a problem