Class ShadowFractions
ShadowConf.
Each method here samples a particular falloff curve f(t) (shadow intensity as a
function of the normalized distance t in [0, 1] away from the solid edge
of the shadow) at evenly spaced positions and returns the resulting fractions as a
Tuple of float values, as described by
ShadowFractionsSupplier.
The functions in this class are also supposed to serve as an example which demonstrates
how to create custom shadow falloff curves yourself. See UI.ShadowType
for the real world phenomenon and the exact math behind each curve.
-
Method Summary
Modifier and TypeMethodDescriptionstatic sprouts.Tuple<Float> blur()The exact edge profile of a hard edge convolved with a Gaussian kernel, which is the normalized error function (NOT a bell shape).static sprouts.Tuple<Float> bounce()Ease-out-bounce, inverted so the shadow settles toward transparency.static sprouts.Tuple<Float> contact()A sharp drop near the edge with a long faint tail, normalized to 0 att == 1.static sprouts.Tuple<Float> flat()A constant rate fade from full shadow color to transparency, producing a perfectly straight falloff.static sprouts.Tuple<Float> glow()A bell shaped (Gaussian) falloff, normalized so it reaches exactly 0 att == 1.static sprouts.Tuple<Float> penumbra()A smooth, symmetric S-curve, a cheap polynomial approximation ofblur().static sprouts.Tuple<Float> ripple()A cosine wave under a linear decay envelope: fading concentric rings.static sprouts.Tuple<Float> sawtooth()Repeating linear ramps under a decay envelope: fading louvers.static sprouts.Tuple<Float> stairs()Posterize the linear falloff intoNdiscrete bands (cel-shaded look).
-
Method Details
-
flat
A constant rate fade from full shadow color to transparency, producing a perfectly straight falloff. Falloff:f(t) = 1 - t. As a straight line is fully described by its two endpoints, this needs only two fractions and so allocates the smallest possible tuple. -
penumbra
A smooth, symmetric S-curve, a cheap polynomial approximation ofblur(). Falloff (the "smoothstep" function):f(t) = 1 - t2(3 - 2t). -
blur
The exact edge profile of a hard edge convolved with a Gaussian kernel, which is the normalized error function (NOT a bell shape). This is what a CSS box-shadow / Figma / Photoshop blur looks like.Falloff (normalized error function, with steepness
k):
f(t) = (erf(k/2) - erf(k(t - 1/2))) / (2 * erf(k/2)) -
glow
A bell shaped (Gaussian) falloff, normalized so it reaches exactly 0 att == 1. Mimics a diffuse glow / halo rather than a cast shadow edge.Falloff (normalized Gaussian bell, with width
k):
f(t) = (exp(-k t2) - exp(-k)) / (1 - exp(-k)) -
contact
A sharp drop near the edge with a long faint tail, normalized to 0 att == 1. Mimics a contact shadow / ambient occlusion.Falloff (normalized exponential decay, with rate
k):
f(t) = (exp(-k t) - exp(-k)) / (1 - exp(-k)) -
stairs
Posterize the linear falloff intoNdiscrete bands (cel-shaded look).Falloff (quantized linear, with
Nbands):
f(t) = round((1 - t) * (N - 1)) / (N - 1) -
ripple
A cosine wave under a linear decay envelope: fading concentric rings.Falloff (damped cosine, with
kripples):
f(t) = (1 - t) * (1/2 + 1/2 * cos(2πk t)), withk = 3 -
sawtooth
Repeating linear ramps under a decay envelope: fading louvers.Falloff (decaying sawtooth, with
klouvers):
f(t) = (1 - t) * (1 - frac(k t)), withk = 4 -
bounce
Ease-out-bounce, inverted so the shadow settles toward transparency. Falloff:f(t) = 1 - easeOutBounce(t).
-