SphericalHarmonicsL2[] An array of SphericalHarmonicsL2 coefficients, one per probe.
Gets the spherical harmonics coefficients of the baked light probes stored in this LightProbes object.
The returned array contains one SphericalHarmonicsL2 value for each light probe stored in this LightProbes object, in the same order as the positions returned by LightProbes.GetPositionsSelf.
Additional resources: LightProbes.SetSHCoefficientsSelf, LightProbes.countSelf, SphericalHarmonicsL2.
// Attach this script to a GameObject in a scene that contains baked light probes, // then enter Play mode. The script reads the LightProbes object for the scene // and logs the average spherical harmonics coefficients across all probes.
using UnityEngine; using UnityEngine.Rendering;
public class GetSHCoefficientsSelfExample : MonoBehaviour { void Start() { LightProbes probes = LightProbes.GetSharedLightProbesForScene(gameObject.scene); if (probes == null || probes.countSelf == 0) { Debug.Log("The scene contains no baked light probes."); return; }
SphericalHarmonicsL2[] coefficients = probes.GetSHCoefficientsSelf();
SphericalHarmonicsL2 sum = new SphericalHarmonicsL2(); foreach (SphericalHarmonicsL2 sh in coefficients) { sum += sh; } SphericalHarmonicsL2 average = sum * (1.0f / coefficients.Length);
for (int rgb = 0; rgb < 3; rgb++) { string channel = rgb == 0 ? "R" : rgb == 1 ? "G" : "B"; for (int coefficient = 0; coefficient < 9; coefficient++) { Debug.Log($"Average {channel}[{coefficient}] = {average[rgb, coefficient]}"); } } } }