/// <summary> /// Repacks all of the spherical harmonics coefficients used by probes to be used in shaders /// </summary> /// <param name="rawCoefficients">The input spherical harmonic coefficients</param> /// <returns>The repacked coefficients, ready to be used in shaders</returns> public static SphericalHarmonicsCoefficients RepackForShaders(this SphericalHarmonicsL2 rawCoefficients) { // https://docs.unity3d.com/Manual/LightProbes-TechnicalInformation.html -> http://www.ppsloan.org/publications/StupidSH36.pdf -> Appendix A10 : "Shader/CPU code for Irradiance Environment Maps" SphericalHarmonicsCoefficients repackedCoefficients = new SphericalHarmonicsCoefficients(); repackedCoefficients.firstBandCoefficients = rawCoefficients.RepackFirstBandForShaders(); repackedCoefficients.shBr.x = rawCoefficients[0, 4]; repackedCoefficients.shBr.y = rawCoefficients[0, 5]; repackedCoefficients.shBr.z = rawCoefficients[0, 6] * 3.0f; repackedCoefficients.shBr.w = rawCoefficients[0, 7]; repackedCoefficients.shBg.x = rawCoefficients[1, 4]; repackedCoefficients.shBg.y = rawCoefficients[1, 5]; repackedCoefficients.shBg.z = rawCoefficients[1, 6] * 3.0f; repackedCoefficients.shBg.w = rawCoefficients[1, 7]; repackedCoefficients.shBb.x = rawCoefficients[2, 4]; repackedCoefficients.shBb.y = rawCoefficients[2, 5]; repackedCoefficients.shBb.z = rawCoefficients[2, 6] * 3.0f; repackedCoefficients.shBb.w = rawCoefficients[2, 7]; repackedCoefficients.shC.x = rawCoefficients[0, 8]; repackedCoefficients.shC.y = rawCoefficients[1, 8]; repackedCoefficients.shC.z = rawCoefficients[2, 8]; repackedCoefficients.shC.w = 1.0f; return(repackedCoefficients); }
/// <summary> /// Updates the spherical harmonics coefficients /// </summary> public void Update() { _coefficients = RenderSettings.ambientProbe.RepackForShaders(); }