run method
Returns linear RGBA for attachment zero. Null discards the fragment.
Implementation
@override
Vector4? run(Float32List v, ShaderBindings b, FragmentContext c) {
final src = bloomSource(b);
if (src == null) return Vector4(0.0, 0.0, 0.0, 1.0);
// The radius is in source texels, and is what makes the chain a filter
// rather than four copies of the same blur.
final radius = math.max(src.params.z, 0.0);
final tx = src.tx * radius;
final ty = src.ty * radius;
final u = v[0];
final w = v[1];
Vector3 at(double dx, double dy) {
final t = src.source.sample(u + dx * tx, w + dy * ty);
return Vector3(t.x, t.y, t.z);
}
final a = at(-1, 1), bb = at(0, 1), cc = at(1, 1);
final d = at(-1, 0), e = at(0, 0), f = at(1, 0);
final g = at(-1, -1), h = at(0, -1), i = at(1, -1);
var result = e * 4.0 + (bb + d + f + h) * 2.0 + (a + cc + g + i);
result.scale(1.0 / 16.0);
// The ratio of this level's weight and warmth to the one above's — see
// `bloom_upsample.frag` for why a ratio and not the warmth itself.
final tint = b.vec4('BloomInfo', 'tint', Vector4(1.0, 1.0, 1.0, 1.0));
result = Vector3(result.x * tint.x, result.y * tint.y, result.z * tint.z);
return Vector4(result.x, result.y, result.z, 1.0);
}