run method
Returns linear RGBA for attachment zero. Null discards the fragment.
Implementation
@override
Vector4? run(Float32List v, ShaderBindings b, FragmentContext c) {
final fog = b.vec4('FogInfo', 'fog', Vector4.zero());
// `TowardsEyeFrom`: to the eye, or against the view axis through an
// orthographic lens — `P7`.
final towards = towardsEyeFrom(b, v[4], v[5], v[6]);
var facing = 1.0;
if (towards.length2 > 0.0) {
final n = Vector3(v[7], v[8], v[9]);
final length = n.length;
if (length > 0.0) {
// `abs`, because nothing here is culled and a back face is as visible
// as a front one.
facing = (n.dot(towards) / length).abs();
}
}
// Never to zero: a silhouette edge is exactly perpendicular to the eye, and
// a face that vanished there would carve a dark seam along it.
final intensity = 0.35 + 0.65 * facing;
var fogged = 1.0;
if (fog.w > 0.0) {
fogged = math
.exp(-fog.w * fogDistance(b, v[4], v[5], v[6]))
.clamp(0.0, 1.0);
}
final scale = v[3] * intensity * fogged;
return Vector4(v[0] * scale, v[1] * scale, v[2] * scale, 1.0);
}