run method

  1. @override
Vector4? run(
  1. Float32List v,
  2. ShaderBindings b,
  3. FragmentContext c
)
override

Returns linear RGBA for attachment zero. Null discards the fragment.

Implementation

@override
Vector4? run(Float32List v, ShaderBindings b, FragmentContext c) {
  final weights = b.textures['weight_texture'];
  if (weights == null) return Vector4(0.0, 0.0, 0.0, 1.0);
  final step = b.vec4('LocalExposureBlurInfo', 'step', Vector4.zero());
  final stops = b.vec4('LocalExposureBlurInfo', 'stops', Vector4.zero());
  final sum = Vector3.zero();
  var total = 0.0;
  for (var i = -6; i <= 6; i++) {
    final w = math.exp(-(i * i) / 18.0);
    final t = weights.sample(v[0] + step.x * i, v[1] + step.y * i);
    sum.addScaled(Vector3(t.x, t.y, t.z), w);
    total += w;
  }
  sum.scale(1.0 / total);
  if (step.z > 0.5) {
    final shift =
        (sum.x * stops.x - sum.z * stops.y) /
        math.max(sum.x + sum.y + sum.z, 1e-6);
    return Vector4(shift, shift, shift, 1.0);
  }
  return Vector4(sum.x, sum.y, sum.z, 1.0);
}