evaluateDiffuseSphericalHarmonics function Lighting and environment
Evaluates diffuse spherical harmonics sh for a surface normal
direction, returning the linear RGB radiance a white Lambertian surface
reflects.
This is exactly the polynomial the standard shader evaluates, so it is the
reference for checking coefficients produced elsewhere. Coefficients must
already fold in the Lambertian cosine convolution (A_l) and the 1/pi
BRDF term; see describeDiffuseSphericalHarmonics.
Implementation
Vector3 evaluateDiffuseSphericalHarmonics(List<Vector3> sh, Vector3 direction) {
if (sh.length != kDiffuseShCoefficientCount) {
throw ArgumentError.value(
sh.length,
'sh',
'Expected $kDiffuseShCoefficientCount coefficients',
);
}
final normal = direction.normalized();
final basis = Float64List(kDiffuseShCoefficientCount);
_evaluateShBasis(normal, basis);
final result = Vector3.zero();
for (var i = 0; i < kDiffuseShCoefficientCount; i++) {
result.x += sh[i].x * basis[i];
result.y += sh[i].y * basis[i];
result.z += sh[i].z * basis[i];
}
return result;
}