run method
Returns linear RGBA for attachment zero. Null discards the fragment.
Implementation
@override
Vector4? run(Float32List v, ShaderBindings b, FragmentContext c) {
final scene = b.textures['scene_texture'];
if (scene == null) return Vector4(1.0, 1.0, 1.0, 1.0);
final stops = b.vec4('LocalExposureInfo', 'stops', Vector4.zero());
final tx = stops.z * 2.0;
final ty = stops.w * 2.0;
final camera = b.vec4('LocalExposureInfo', 'camera', Vector4.zero());
// At the frame's own exposure, which the composite applies after the
// local stops: see the GLSL.
final y =
math.max(
0.25 *
(_luma(scene.sample(v[0] - tx, v[1] - ty)) +
_luma(scene.sample(v[0] + tx, v[1] - ty)) +
_luma(scene.sample(v[0] - tx, v[1] + ty)) +
_luma(scene.sample(v[0] + tx, v[1] + ty))),
0.0,
) *
math.max(camera.x, 0.0);
final shadow = math.pow(2.0, stops.x).toDouble();
final highlight = math.pow(2.0, -stops.y).toDouble();
return Vector4(
_wellExposed(y * shadow) + 1e-4,
_wellExposed(y) + 1e-4,
_wellExposed(y * highlight) + 1e-4,
1.0,
);
}