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
Compare examples
Compare base-mip sampling with the averaged mip. The coordinate stays fixed while detail changes.
Model assumptionsuv = vec2(0.25, 0.25); filter = linear; mip = nearest; levels = [2 × 2, 1 × 1]
Example 1level = 0
0.75100.25 - Result
0
Example 2level = 1
0.5 - Result
0.5
Example 3level = 0; uv = vec2(0.75, 0.75)
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 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 and GLSL ES 3.00.
Related functions
- 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
declare function textureSampleLevel( tex: texture_2d<f32>, smp: sampler, uv: vec2, level: number,): vec4declare function textureSampleLevel( tex: texture_2d_array<f32>, smp: sampler, uv: vec2, layer: number, level: number,): vec4declare function textureSampleLevel( tex: texture_cube<f32>, smp: sampler, dir: vec3, level: number,): vec4declare function textureSampleLevel( tex: texture_3d<f32>, smp: sampler, coord: vec3, level: number,): vec4declare function textureSampleLevel(tex: texture_1d<f32>, smp: sampler, coord: number, level: number): vec4declare function textureSampleLevel( tex: texture_cube_array<f32>, smp: sampler, dir: vec3, layer: number, level: number,): vec4A 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.
Parameters
-
textexture_2d<f32>texture_2d_array<f32>texture_cube<f32>texture_3d<f32>texture_1d<f32>texture_cube_array<f32> -
smpsampler -
uvoptionalvec2 -
diroptionalvec3 -
coordoptionalvec3number -
levelnumber -
layeroptionalnumber
Return value
Description
On a texture_2d_array the layer comes before the level. Compiles to textureSampleLevel on WGSL and textureLod on GLSL.
Targets
- WGSL
-
textureSampleLevel(a, b, c, d) - GLSL ES 3.00
-
textureLod(a, c, d)