attenuation function

double attenuation(
  1. double distance,
  2. double range
)

PunctualAttenuation: inverse square with glTF's range window.

Implementation

double attenuation(double distance, double range) {
  var attenuation = 1.0 / math.max(distance * distance, 1e-4);
  if (range > 0.0) {
    final ratio = distance / range;
    final window = (1.0 - ratio * ratio * ratio * ratio).clamp(0.0, 1.0);
    attenuation *= window * window;
  }
  return attenuation;
}