build static method

EnvironmentMapData build(
  1. void radiance(
    1. double x,
    2. double y,
    3. double z,
    4. Float32List out,
    ), {
  2. int size = 32,
})

Builds a map from what radiance says each direction holds.

Implementation

static EnvironmentMapData build(
  void Function(double x, double y, double z, Float32List out) radiance, {
  int size = 32,
}) {
  final base = List.generate(6, (_) => Float32List(size * size * 4));
  final c = Float32List(3);
  for (var face = 0; face < 6; face++) {
    final out = base[face];
    for (var row = 0; row < size; row++) {
      for (var col = 0; col < size; col++) {
        final (x, y, z) = directionOf(
          face,
          (col + 0.5) / size,
          (row + 0.5) / size,
        );
        final len = math.sqrt(x * x + y * y + z * z);
        radiance(x / len, y / len, z / len, c);
        final o = (row * size + col) * 4;
        out[o] = c[0];
        out[o + 1] = c[1];
        out[o + 2] = c[2];
        out[o + 3] = 1;
      }
    }
  }
  final levels = <List<Float32List>>[base];
  final count = (math.log(size) / math.ln2).floor() + 1;
  for (var m = 1; m < count; m++) {
    levels.add(_prefilter(base, size, size >> m, m / (count - 1)));
  }
  return EnvironmentMapData._(size, levels, _shOf(base, size));
}