probeFaceDirection function

Vector3 probeFaceDirection(
  1. int face,
  2. double s,
  3. double t
)

The direction the texel at (s, t) of face looks along, with t measured down the face from row zero.

The cube-map table inverted — the same six cases probe_prefilter.frag spells out and EnvironmentMap uses on the host — and it has to stay the inverse of BoundTexture.sampleCube's addressing: a face written from directions its own sampler does not produce is a cube with six seams.

Implementation

Vector3 probeFaceDirection(int face, double s, double t) {
  final u = s * 2.0 - 1.0;
  final v = t * 2.0 - 1.0;
  return switch (face) {
    0 => Vector3(1.0, -v, -u),
    1 => Vector3(-1.0, -v, u),
    2 => Vector3(u, 1.0, v),
    3 => Vector3(u, -1.0, -v),
    4 => Vector3(u, -v, 1.0),
    _ => Vector3(-u, -v, -1.0),
  }..normalize();
}