demo · v142
WebGPU primitive_index
Press render. The page requests a WebGPU adapter with the optional primitive-index feature and draws a triangle fan; each triangle gets a colour straight from the new @builtin(primitive_index) in the fragment shader — no per-vertex colour attribute needed. Below: a static SVG fallback for browsers that can't grab the feature.
feature unavailable
navigator.gpu
—
adapter has 'primitive-index'
—
relevant API
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice({ requiredFeatures: ["primitive-index"] });
// In WGSL:
@fragment
fn fs(@builtin(primitive_index) i: u32) -> @location(0) vec4f {
let r = f32(i & 7u) / 7.0;
return vec4f(r, 1.0 - r, 0.4, 1.0);
}
see also
- WebGPU primitive_index — feature index
- ChromeStatus entry