textureLoad
Function
A texel load reads one stored value at integer coordinates, without sampler interpolation.
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:
texelFetch - GLSL:
imageLoad
Compare examples
Compare the integer coordinates with the selected cell. No neighbouring values are blended.
Model assumptionstexture_2d<f32>; level = 0
Example 1textureLoad(tex, vec2i(0, 0), 0).r
0.75100.25 - Result
0
Example 2textureLoad(tex, vec2i(1, 0), 0).r
0.75100.25 - Result
0.25
Example 3textureLoad(tex, vec2i(1, 1), 0).r
0.75100.25 - 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 exact lookup in image-processing kernels, lookup tables, and multisample inspection.
Inputs and limits
The example reads an in-bounds base-mip texel. Multisampled textures take a sample index instead of a mip level. Keep coordinates in bounds.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
- WGSL
textureLoad(a, b, c)- GLSL ES 3.00
texelFetch(a, b, int(c))
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Reads one texel at the integer coord and mip level without filtering, by a vec2i on a texture_2d, a vec3i on a texture_3d and one integer on a texture_1d; a cube texture has no texel fetch on either target.
Syntax
declare function textureLoad<E extends TextureElem = f32>( tex: texture_2d<E>, coord: TexelCoord2, level: number,): Vec4OfElem<E>declare function textureLoad<E extends TextureElem = f32>( tex: texture_2d_array<E>, coord: TexelCoord2, layer: number, level: number,): Vec4OfElem<E>declare function textureLoad<E extends TextureElem = f32>( tex: texture_3d<E>, coord: TexelCoord3, level: number,): Vec4OfElem<E>declare function textureLoad<E extends TextureElem = f32>( tex: texture_1d<E>, coord: number, level: number,): Vec4OfElem<E>declare function textureLoad<E extends TextureElem = f32>( tex: texture_multisampled_2d<E>, coord: TexelCoord2, sampleIndex: number,): Vec4OfElem<E>declare function textureLoad(tex: texture_depth_multisampled_2d, coord: TexelCoord2, sampleIndex: number): f32declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>( tex: texture_storage_2d<F, A>, coord: TexelCoord2,): StorageTexel<F>declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>( tex: texture_storage_2d_array<F, A>, coord: TexelCoord2, layer: number,): StorageTexel<F>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 carries that row with the compiler's emit.
A signature may name a type the ambient file declares for its own use. These are those declarations.
TextureElemtype TextureElem = f32 | i32 | u32Vec4OfElemtype Vec4OfElem<E> = typeof u32Tag extends keyof E ? vec4u : typeof i32Tag extends keyof E ? vec4i : vec4TexelCoord2type TexelCoord2 = vec2i | vec2uTexelCoord3type TexelCoord3 = vec3i | vec3uStorageFormattype StorageFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm'StorageTexeltype StorageTexel<F extends StorageFormat> = F extends `${string}uint` ? vec4u : F extends `${string}sint` ? vec4i : vec4
Parameters
-
textexture_2d<E>texture_2d_array<E>texture_3d<E>texture_1d<E>texture_multisampled_2d<E>texture_depth_multisampled_2dtexture_storage_2d<F, A>texture_storage_2d_array<F, A> -
coordTexelCoord2TexelCoord3number -
leveloptionalnumber -
layeroptionalnumber -
sampleIndexoptionalnumber
Return value
Vec4OfElem<E>f32StorageTexel<F>
Description
On a texture_2d_array the layer comes before the level, and on a texture_multisampled_2d or texture_depth_multisampled_2d the third argument is the sample index instead of a level. Compiles to textureLoad on WGSL and texelFetch on GLSL, where the lowering of a multisampled texture is not supported yet (Rule 10.5), so a module loading one emits WGSL alone.
Targets
- WGSL
-
textureLoad(a, b, c) - GLSL ES 3.00
-
texelFetch(a, b, int(c))
An author writes the same call on every texture, and the compiler writes what each target needs. GLSL ES 3.00's texelFetch takes a signed coordinate, carries an array layer inside it and has no 1d or multisampled texture.
texture_2d<f32>textureLoad(t, vec2i(1, 2), 0)textureLoad(t, vec2<i32>(1, 2), 0u)texelFetch(t, ivec2(1, 2), int(0u))texture_2d<f32>textureLoad(t, vec2u(1, 2), 0)textureLoad(t, vec2<u32>(1u, 2u), 0u)texelFetch(t, ivec2(uvec2(1u, 2u)), int(0u))texture_3d<f32>textureLoad(t, vec3i(1, 2, 3), 0)textureLoad(t, vec3<i32>(1, 2, 3), 0u)texelFetch(t, ivec3(1, 2, 3), int(0u))texture_3d<f32>textureLoad(t, vec3u(1, 2, 3), 0)textureLoad(t, vec3<u32>(1u, 2u, 3u), 0u)texelFetch(t, ivec3(uvec3(1u, 2u, 3u)), int(0u))texture_2d_array<f32>textureLoad(t, vec2i(1, 2), 3, 0)textureLoad(t, vec2<i32>(1, 2), 3, 0u)texelFetch(t, ivec3(ivec2(1, 2), int(3)), int(0u))texture_2d_array<f32>textureLoad(t, vec2u(1, 2), 3, 0)textureLoad(t, vec2<u32>(1u, 2u), 3, 0u)texelFetch(t, ivec3(ivec2(uvec2(1u, 2u)), int(3)), int(0u))texture_1d<f32>textureLoad(t, 1, 0)textureLoad(t, 1, 0u)No form on this target.
texture_multisampled_2d<f32>textureLoad(t, vec2i(1, 2), 0)textureLoad(t, vec2<i32>(1, 2), 0u)No form on this target.
texture_depth_multisampled_2dtextureLoad(t, vec2i(1, 2), 0)textureLoad(t, vec2<i32>(1, 2), 0u)No form on this target.