smoothstep function

double smoothstep(
  1. double edge0,
  2. double edge1,
  3. double x
)

Implementation

double smoothstep(double edge0, double edge1, double x) {
  // **Two equal edges are a step, not a division.** GLSL leaves this
  // undefined; Dart does not, and what it does is `0/0`, which is a NaN that
  // multiplies through the rest of the shader and comes out as a black pixel
  // nobody can trace back. The engine's own copy in `sky_settings.dart` has had
  // this line since it was written and this one lost it.
  if (edge0 == edge1) return x < edge0 ? 0.0 : 1.0;
  final t = ((x - edge0) / (edge1 - edge0)).clamp(0.0, 1.0);
  return t * t * (3.0 - 2.0 * t);
}