demo · v131
WGSL shader: emit clip_distances
The WGSL vertex shader on the left outputs a four-element clip_distances array. The hardware clips any fragment whose interpolated clip_distances[i] is negative. Adjust the plane equation sliders to move and rotate the clipping plane. The canvas on the right renders the result.
WGSL with clip_distances
enable clip_distances;
struct VsOut {
@builtin(position) pos: vec4f,
@builtin(clip_distances) clip: array<f32, 4>,
@location(0) col: vec4f,
};
@vertex fn vs(@builtin(vertex_index) i: u32) -> VsOut {
let p = positions[i];
var o: VsOut;
o.pos = vec4f(p, 1.0);
let plane = vec4f(planeN, planeD);
o.clip[0] = dot(plane, vec4f(p, 1.0));
o.col = vec4f(0.0, 0.1, 0.7, 1.0);
return o;
}
output preview
fallback rendering
The preview canvas uses 2D rasterisation as a fallback so the demo works without WebGPU access. The actual semantics — a plane equation, half-space clip — are identical.