home/ atoms/ soft-shadows-sdf-penumbra

SDF soft shadows track how close the shadow ray comes to occluders, not just whether it hits them

Hard shadow rays only record a binary hit/miss. SDF soft shadows exploit the distance information available at each marching step: at each point along the shadow ray, record the ratio of the current SDF value to how far the ray has traveled. The minimum of these ratios over the full ray gives a penumbra factor — rays that nearly grazed an occluder get a lower factor than rays that flew through empty space. Dividing by travel distance makes distant occluders cast wider penumbras than nearby ones. The softness parameter k controls the transition width and is artistically controllable.

Examples

float res=1.0; for(float t=tmin;t<tmax;){ float h=map(ro+rd*t); res=min(res, k*h/t); t+=h; } return clamp(res,0.,1.);

Assessment

Increase k from 8 to 64 in a soft shadow implementation and describe the visual change. Why does increasing k produce sharper rather than softer shadows?

“if the ray happens to struggle to make it to the light source, because it's getting close to other objects, even though it doesn't hit them, if it's really close to them, you can kind of measure that”
corpus · inigo-quilez-live-coding-happy-jumping-video · chunk 9