Skip to main content

Module shape_sdf

Module shape_sdf 

Source
Expand description

CPU mirror of the signed-distance functions in shaders/shape.wgsl.

The software (pixels) renderer rasterizes the same shapes as the GPU. Both evaluate these formulas, so a stroked rect or an arc looks the same on either backend instead of the CPU path quietly degrading to a filled box.

Angle convention (shared with cranpose_ui_graphics::stroke): radians, 0 along +X, increasing clockwise on screen (y-down device space).

Functions§

arc_coverage
Coverage of point by an arc band.
coverage_for_distance
Antialiased coverage for a signed distance, matching the shader’s 1.0 - smoothstep(-0.5, 0.5, d).
sdf_arc_band
Signed distance to a circular band limited to an angular sweep — the shape behind both stroked arcs and filled annular sectors.
sdf_rounded_rect
Signed distance to a rounded box centered at the origin.
sdf_stroked_rounded_rect
Signed distance to the outline of a rounded box stroked with a centered stroke of width 2 * half_width.
stroked_rect_coverage
Coverage of point by a stroked rect/round-rect whose (already inflated) bounds are rect.