textureGatherCompare
On this page

textureGatherCompare

Function

Depth comparison tests a reference depth against stored depths through a comparison sampler. Gather returns each comparison separately.

Compare examples

Raise the reference depth and observe which texels pass. The example sampler uses less-equal comparison.

Model assumptionsdepth = [[0.75, 1], [0, 0.25]]; compare = less-equal; filter = linear; level = 0; uv = vec2(0.5, 0.5)

Example 1textureGatherCompare(tex, smp, uv, 0.2)
truetruefalsetrue
Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.
Result
vec4(1, 1, 1, 0)
Example 2textureGatherCompare(tex, smp, uv, 0.5)
truetruefalsefalse
Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.
Result
vec4(1, 1, 0, 0)
Example 3textureGatherCompare(tex, smp, uv, 0.8)
falsetruefalsefalse
Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.
Result
vec4(0, 1, 0, 0)

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 shadow tests: compare a surface depth with the nearest depth recorded from the light.

Inputs and limits

The four outputs follow gather order and are not averaged. This compiler emits this operation for WebGPU only.

For shader input rules and precision, consult WGSL and GLSL ES 3.00.

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

Compares the reference depth ref against the four texels a linear filter would blend at the coordinate on mip level 0, through the comparison sampler smp, and returns the four results (0 or 1 each) as a vec4 in the order (umin,vmax), (umax,vmax), (umax,vmin), (umin,vmin), in any stage.

Syntax

declare function textureGatherCompare(
tex: texture_depth_2d,
smp: sampler_comparison,
uv: vec2,
ref: number,
): vec4
declare function textureGatherCompare(
tex: texture_depth_2d_array,
smp: sampler_comparison,
uv: vec2,
layer: number,
ref: number,
): vec4
declare function textureGatherCompare(
tex: texture_depth_cube,
smp: sampler_comparison,
dir: vec3,
ref: number,
): vec4
declare function textureGatherCompare(
tex: texture_depth_cube_array,
smp: sampler_comparison,
dir: vec3,
layer: number,
ref: 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 carries that row with the compiler's emit.

Parameters

Return value

vec4

Description

On a texture_depth_2d_array or a texture_depth_cube_array the layer comes before the reference. Compiles to textureGatherCompare on WGSL; its GLSL lowering is not supported yet (Rule 10.5), so a module using it emits WGSL alone.

Targets

WGSL
textureGatherCompare(a, b, c, d)
GLSL ES 3.00
textureGatherCompare is not supported yet on the WebGL2 tier (Rule 10.5)

Examples

See also

Edit this page Report a problem