Skip to main content

Module shadow

Module shadow 

Source
Expand description

Shadows: a box’s shape blurred by a true Gaussian, as display-list commands both backends replay.

Neither vello’s blurred rounded rectangle — one radius for all four corners — nor any filter both backends share draws that, so the engine computes the blur itself, sampling the shape every half standard deviation, which is fine enough that the samples, drawn smoothly, are the blur at any zoom.

A small shadow is one image of those samples. A large one would need too many — a 16,000-pixel box blurred by 2 has a billion — but away from its corners a blurred rounded rectangle doesn’t vary along its edges, so it is drawn as pieces instead: solid where the blur can’t reach, each edge’s one-dimensional profile stretched along it, and each corner on its own — sampled in two dimensions, or for a corner far rounder than the blur, the exact blur of a disc’s edge as a radial gradient. The pieces meet edge to edge, each added to what is under it, so no seam shows where two meet at any zoom; together, in one layer at the shadow color’s opacity, they are the shadow. An ellipse that isn’t a circle has no straight edges, so its shadow is tiled: solid tiles inside, sampled tiles along its edge, nothing outside.

Enums§

Outline
The shape a shadow blurs: a rounded rectangle — each corner’s radius as kurbo clamps it — or an ellipse.

Constants§

SINGLE
The most samples a shadow drawn as one image may have, and its longest side.

Functions§

shadow
Adds outline’s shadow — blurred by a Gaussian of std_dev pixels and colored c — to list, and each image it paints, in order, to images.
shadow_with
shadow, drawing one image when it takes no more than single samples.