writeLit function

Vector4 writeLit(
  1. FragmentContext c,
  2. Float32List v,
  3. ShaderBindings b, {
  4. required Vector3 color,
  5. required double alpha,
  6. required Vector3 normal,
  7. required double roughness,
  8. double passThrough = 0.0,
})

WriteSurface from color.glsl: the lit colour, faded by the fog, written beside the surface geometry.

One function rather than two calls at each of five sites, because that is what the GLSL is — there the fog and the geometry are written together, and a transcription that splits them is one where a shader can be fogged and the next one forgotten. That is exactly what had happened: of everything drawn, only the three particle shaders faded with distance, and every road, wall and car was drawn at full contrast to the horizon. A test that passed FogSettings to this rasteriser was measuring a renderer with no weather.

Implementation

Vector4 writeLit(
  FragmentContext c,
  Float32List v,
  ShaderBindings b, {
  required Vector3 color,
  required double alpha,
  required Vector3 normal,
  required double roughness,

  /// How much light a transmissive surface lets through, nought to one.
  double passThrough = 0.0,
}) {
  writeSurface(c, v, b, normal, roughness);
  // `g_premultiply`: a blended material's colour is weighted by its alpha,
  // after the fog, because the blend takes its source premultiplied.
  final weight = premultiplies(b) ? alpha : 1.0;
  final fogged = applyFog(color, v, b);
  return writeWeightedBlended(
    c,
    v,
    b,
    // `g_pass_through`: a thin pane lets that share of what is behind it
    // through the blend.
    Vector4(
      fogged.x * weight,
      fogged.y * weight,
      fogged.z * weight,
      alpha * (1.0 - passThrough),
    ),
  );
}