composeAlpha static method

  1. @visibleForTesting
double composeAlpha({
  1. required double shadowVisibility,
  2. required double occlusion,
  3. required double shadowIntensity,
  4. required double aoStrength,
  5. double radialDistance = 0.0,
  6. double fadeStart = 0.0,
  7. double fadeEnd = 0.0,
})

The catcher's composed straight alpha, the same math the shader runs.

shadowVisibility and occlusion are 1 fully lit/unoccluded to 0 fully dark; radialDistance is the fragment's distance from the mesh origin in local units.

Implementation

@visibleForTesting
static double composeAlpha({
  required double shadowVisibility,
  required double occlusion,
  required double shadowIntensity,
  required double aoStrength,
  double radialDistance = 0.0,
  double fadeStart = 0.0,
  double fadeEnd = 0.0,
}) {
  final shadowTerm = shadowIntensity * (1.0 - shadowVisibility);
  final aoTerm = aoStrength * (1.0 - occlusion);
  var radialFade = 1.0;
  if (fadeEnd > fadeStart) {
    final t = ((radialDistance - fadeStart) / (fadeEnd - fadeStart)).clamp(
      0.0,
      1.0,
    );
    radialFade = 1.0 - t * t * (3.0 - 2.0 * t);
  }
  return (shadowTerm + aoTerm).clamp(0.0, 1.0) * radialFade;
}