encodeDiffuseShSidecar function Lighting and environment

Uint8List encodeDiffuseShSidecar(
  1. List<Vector3> sh
)

Encodes sh as the engine's diffuse spherical-harmonic sidecar: kDiffuseShCoefficientCount RGB triples of little-endian 32-bit float, coefficient-major (c0.r, c0.g, c0.b, c1.r, ...), for kDiffuseShSidecarByteLength bytes total and no header.

The same bytes go in a KTX2 file's kDiffuseShKtx2Key key/value entry.

Implementation

Uint8List encodeDiffuseShSidecar(List<Vector3> sh) {
  if (sh.length != kDiffuseShCoefficientCount) {
    throw ArgumentError.value(
      sh.length,
      'sh',
      'Expected $kDiffuseShCoefficientCount coefficients',
    );
  }
  final out = ByteData(kDiffuseShSidecarByteLength);
  for (var i = 0; i < kDiffuseShCoefficientCount; i++) {
    out.setFloat32(i * 12, sh[i].x, Endian.little);
    out.setFloat32(i * 12 + 4, sh[i].y, Endian.little);
    out.setFloat32(i * 12 + 8, sh[i].z, Endian.little);
  }
  return out.buffer.asUint8List();
}