Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

LightProbes.GetSHCoefficientsSelf

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public SphericalHarmonicsL2[] GetSHCoefficientsSelf();

Returns

SphericalHarmonicsL2[] An array of SphericalHarmonicsL2 coefficients, one per probe.

Description

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]}"); } } } }