writeWeightedBlended function

Vector4 writeWeightedBlended(
  1. FragmentContext c,
  2. Float32List v,
  3. ShaderBindings b,
  4. Vector4 color,
)

WriteWeightedBlended from color.glsl — R8: color as it stands unless FogInfo.forward.w asks for the accumulation target's share (1), the revealage target's (2), or both, the second into attachment one (3).

Implementation

Vector4 writeWeightedBlended(
  FragmentContext c,
  Float32List v,
  ShaderBindings b,
  Vector4 color,
) {
  final mode = b.vec4('FogInfo', 'forward', Vector4.zero()).w;
  if (mode <= 0.5) return color;
  final alpha = color.w;
  final weight = weightedBlendedWeight(alpha, v, b);
  if (mode > 2.5) c.surface = Vector4.all(alpha);
  return mode > 1.5 && mode < 2.5
      ? Vector4.all(alpha)
      : Vector4(
          color.x * weight,
          color.y * weight,
          color.z * weight,
          alpha * weight,
        );
}