run method
Returns linear RGBA for attachment zero. Null discards the fragment.
Implementation
@override
Vector4? run(Float32List v, ShaderBindings b, FragmentContext c) {
final source = b.textures['source_texture'];
if (source == null) return Vector4.zero();
final params = b.vec4('SmaaInfo', 'params', Vector4(0.0, 0.0, 0.1, 2.0));
double at(double dx, double dy) =>
_luma(source.sample(v[0] + dx * params.x, v[1] + dy * params.y));
final middle = at(0.0, 0.0);
final left = at(-1.0, 0.0);
final top = at(0.0, -1.0);
final deltaLeft = (middle - left).abs();
final deltaTop = (middle - top).abs();
var edgeLeft = _step(params.z, deltaLeft);
var edgeTop = _step(params.z, deltaTop);
if (edgeLeft + edgeTop == 0.0) return Vector4.zero();
// Local contrast adaptation: a step is not an edge when a much larger
// one sits right beside it, which is what keeps the inside of a
// high-contrast texture from being smoothed as a staircase.
final right = (middle - at(1.0, 0.0)).abs();
final bottom = (middle - at(0.0, 1.0)).abs();
final leftLeft = (left - at(-2.0, 0.0)).abs();
final topTop = (top - at(0.0, -2.0)).abs();
final largest = math.max(
math.max(math.max(deltaLeft, deltaTop), math.max(right, bottom)),
math.max(leftLeft, topTop),
);
edgeLeft *= _step(largest, params.w * deltaLeft);
edgeTop *= _step(largest, params.w * deltaTop);
return Vector4(edgeLeft, edgeTop, 0.0, 0.0);
}