clipPlugin
import {clipPlugin} from '@luma.gl/shaders/plugins';
clipPlugin provides coordinate-system-neutral rectangular clipping.
It declares a smooth clipCoordinates: vec2<f32> inter-stage variable and a clip shader
module with these props:
export type ClipPluginProps = {
enabled?: boolean;
bounds?: readonly [number, number, number, number];
mode?: 'instance' | 'geometry';
};
Defaults are {enabled: true, bounds: [0, 0, 1, 1], mode: 'geometry'}.
Lower bounds are inclusive and upper bounds are exclusive. Coordinates and
bounds must use the same application-defined coordinate system.
Compatible shaders register and call both targets:
- GLSL
- WGSL
vs:CLIP_POSITION(
inout vec4 position,
vec2 instanceCoordinates,
vec2 geometryCoordinates
)
fs:CLIP_COLOR(inout vec4 color)
vs:CLIP_POSITION(
position: ptr<function, vec4<f32>>,
instanceCoordinates: vec2<f32>,
geometryCoordinates: vec2<f32>
)
fs:CLIP_COLOR(color: ptr<function, vec4<f32>>)
The vertex target always stores geometryCoordinates in the generated inter-stage variable.
In instance mode, an out-of-bounds instanceCoordinates value moves the
complete object outside clip space. In geometry mode, the fragment target
discards pixels whose interpolated coordinates are outside the bounds.
model.shaderInputs.setProps({
clip: {enabled: true, mode: 'geometry', bounds: [-0.5, -0.5, 0.5, 0.5]}
});
This update changes only the managed clip uniforms. It does not rebuild the model, buffers, shaders, or pipeline.