v146 · Sampler Gallery

Sampler Gallery

WGSL let declarations for textures and samplers allow reuse without repeating the binding annotation. This gallery renders the same checkerboard texture with six different sampler configurations — nearest vs linear filter, and three address modes — using the let binding style from Chrome 146.

This gallery uses the 2D Canvas API to simulate WebGPU sampler outputs. Real WebGPU texture/sampler let bindings require Chrome 146+ with WebGPU available (chrome://flags/#enable-unsafe-webgpu on some platforms).

WGSL texture/sampler let binding (Chrome 146)

// Chrome 146: texture and sampler can now be bound via `let` // No need to repeat @group/@binding annotations on every use @group(0) @binding(0) var myTexture: texture_2d<f32>; @group(0) @binding(1) var mySampler: sampler; @fragment fn fragMain(in: VertexOutput) -> @location(0) vec4<f32> { // Chrome 146: bind via let — reuse the same binding multiple times let tex = myTexture; let smp = mySampler; let color1 = textureSample(tex, smp, in.uv); let color2 = textureSample(tex, smp, in.uv * 2.0); // reuse let color3 = textureSample(tex, smp, in.uv + vec2(0.5, 0.0)); // reuse return mix(mix(color1, color2, 0.5), color3, 0.25); } // Before Chrome 146: had to use the resource directly each time, // which prevented certain WGSL optimisations and made code verbose.