run method
Returns linear RGBA for attachment zero. Null discards the fragment.
Implementation
@override
Vector4? run(Float32List v, ShaderBindings bindings, FragmentContext c) {
final source = bindings.textures['static_shadow_texture'];
if (source == null) return null;
final tile = bindings.vec4('ShadowCopyInfo', 'tile', Vector4.zero());
final shift = bindings.vec4('ShadowCopyInfo', 'shift', Vector4.zero());
final fromU = v[0] - shift.x;
final fromV = v[1] - shift.y;
final inside = fromU >= 0.0 && fromU <= 1.0 && fromV >= 0.0 && fromV <= 1.0;
final stored = source
.sample(
tile.x + fromU.clamp(0.0, 1.0) * tile.z,
tile.y + fromV.clamp(0.0, 1.0) * tile.w,
)
.x;
// Nothing stays nothing: the far end is not a depth the move shifts. One
// the ordinary way round, nought turned round, and mode two writes the
// turned map back the ordinary way — `A2.8`, as `shadow_copy.frag`.
final mode = shift.w;
final nothing = mode > 0.5 ? 0.0 : 1.0;
final moved = inside && stored != nothing
? (stored + shift.z).clamp(0.0, 1.0)
: nothing;
final depth = mode > 1.5 ? 1.0 - moved : moved;
c.fragDepth = depth;
return Vector4(depth, 0.0, 0.0, 1.0);
}