computeDiffuseSphericalHarmonics static method
Projects an equirectangular radiance image onto 9 L2 spherical- harmonic coefficients suitable for diffuse irradiance.
The image is interpreted as sRGB-encoded and read in the same
equirectangular convention the runtime shader samples with. The
returned coefficients already fold in the Lambertian cosine
convolution (the A_l band factors) and the 1 / pi BRDF term, so
the shader just evaluates Sum c_i * Y_i(n) and multiplies by the
diffuse albedo.
Implementation
static Future<List<Vector3>> computeDiffuseSphericalHarmonics(
ui.Image equirectangular,
) async {
final byteData = await equirectangular.toByteData(
format: ui.ImageByteFormat.rawRgba,
);
if (byteData == null) {
throw Exception('Failed to read RGBA data from environment image.');
}
return _projectEquirectToSphericalHarmonics(
byteData.buffer.asUint8List(),
equirectangular.width,
equirectangular.height,
);
}