run method
Returns linear RGBA for attachment zero. Null discards the fragment.
Implementation
@override
Vector4? run(Float32List v, ShaderBindings b, FragmentContext c) {
final velocity = b.textures['velocity_texture'];
if (velocity == null) return Vector4(0.0, 0.0, 0.0, 1.0);
final source = b.vec4('TileMaxInfo', 'source', Vector4.zero());
final params = b.vec4('TileMaxInfo', 'params', Vector4.zero());
final target = b.vec4('TileMaxInfo', 'target', Vector4.zero());
final taps = (params.w + 0.5).floor();
final tileX = (v[0] * target.x).floorToDouble();
final tileY = (v[1] * target.y).floorToDouble();
// `mix(1, taps, walk)`, per axis.
final startX = tileX * (1.0 + (taps - 1.0) * source.z);
final startY = tileY * (1.0 + (taps - 1.0) * source.w);
var longest = Vector2.zero();
var longestSpan = 0.0;
for (var i = 0; i < 64 && i < taps; i++) {
final at = velocity.sample(
(startX + source.z * i + 0.5) * source.x,
(startY + source.w * i + 0.5) * source.y,
);
final motion = _halfMotion(at.x, at.y, params, params.z);
final span = motion.dot(motion);
if (span > longestSpan) {
longest = motion;
longestSpan = span;
}
}
return Vector4(longest.x, longest.y, 0.0, 1.0);
}