Move your pointer to move the light.

0:01 / 0:30
Playback speed

Soft shadow

Hold the light still on one side of the block and toggle softness. Look for the band between light and dark.

Interactive demo#ShadowsINSIDE#Shadow

A shadow with a blurred edge, because the light has a size.

A pin-point light gives a knife-edge shadow. A bigger light is partly hidden near the edge, so the shadow fades out gradually; that fading band is the penumbra. Turn it off to compare with a hard shadow.

Code

src/demos/soft_shadow.goose
namespace soft_shadow_lesson;
import stage;
import std;
import math;

export "soft-shadow" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    let soft = toggle("on");
    let x = if hover { px } else { 80 + cos(time * 0.8) * 50 };
    let y = if hover { py } else { 50 + sin(time * 0.8) * 30 };
    lit_floor(x, y);
    if soft {
        for i in 14 {
            cast_shadow(66, 38, 26, 22, x + cos(i * 0.449) * 9, y + sin(i * 0.449) * 9, "rgba(14,15,38,.13)");
        }
    } else { cast_shadow(66, 38, 26, 22, x, y, "rgba(14,15,38,.82)"); }
    draw_block(66, 38, 26, 22);
    let radius = if soft { 9 } else { 2 };
    ell(x, y, radius, radius, SUN);
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.