Skip to main content

sketchStroke

Reusable GLSL and WGSL fragment coverage for solid or pencil-like strokes. Import sketchStroke and SketchStrokeProps from @luma.gl/shadertools.

Call sketchStroke_getCoverage(coordinates, strokeLength, seed) in a fragment shader. The first coordinate is normalized distance along the segment; the second is signed transverse distance in the same units as strokeLength, width, jitter, and extension. Pixel units are the default; world-unit adapters can set minimumAntialias: 0 to use fragment derivatives. The result is scalar coverage to multiply into output alpha. Supply a stable, geometry-owned numeric seed.

PropertyDefaultMeaning
width2Full line width in coordinate units
jitter0.7Maximum centerline displacement in coordinate units
variation0.35Fractional width variation, 0–1
grain0.45Pencil grain strength, 0–1
extension3Endpoint overshoot in coordinate units
minimumAntialias0.7Minimum antialiasing distance in coordinate units; 0 uses derivatives
sketch1Set to 0 for solid lines

The caller supplies expanded geometry, projection, depth testing, color, and blending. Reserve the stroke width, jitter, and extension plus the antialiasing fringe. For pixel coordinates, use at least width * 0.65 + jitter + 1 transverse pixels and extension + 1 longitudinal pixels. World-unit geometry must reserve enough space for the projected fragment footprint. Pixel-sized perspective geometry should supply linearly interpolated screen coordinates (or equivalent homogeneous compensation). This module does not generate mesh edges, connect paths, or schedule animation.