atlasDistance function
PointShadowDistance: one comparison against the atlas.
The clamp is applied after the offset, holding each tap inside its own tile individually. Clamping the centre and then offsetting would let the outer taps walk into a distance measured from a different face, or from a different light.
Implementation
double atlasDistance(
ShaderBindings b,
double u,
double v,
double ox,
double oy,
double tileX,
double tileY,
double range,
double inset,
) {
final localU = (u + ox).clamp(inset, 1.0 - inset);
final localV = (v + oy).clamp(inset, 1.0 - inset);
final atlasU = (localU + tileX) / 6.0;
final atlasV = (localV + tileY) / shadowSlots;
final dynamicMap = b.textures['point_shadow_texture'];
final staticMap = b.textures['point_shadow_static_texture'];
var nearest = 1.0;
if (dynamicMap != null) nearest = dynamicMap.sample(atlasU, atlasV).x;
if (staticMap != null) {
// Whichever is nearer occludes: a wall in front of a monster shadows, and
// so does a monster in front of a wall.
nearest = math.min(nearest, staticMap.sample(atlasU, atlasV).x);
}
return nearest * range;
}