private void Start()
        {
            if (computeShader == null)
            {
                throw new System.InvalidOperationException("Compute shader not set!");
            }
            if (_instance != null)
            {
                throw new System.InvalidOperationException("AtmosphereScatteringLutManager already exists!");
            }
            _instance = this;
            AtmLutHelper.Init(computeShader);
            for (int i = 0; i < pingPongUpdaters.Length; i++)
            {
                pingPongUpdaters[i]      = new ProgressiveLutUpdater(null, lutConfig, this);
                pingPongUpdaters[i].name = "Updater " + i;
            }

            //Quickly complete two set luts.
            for (int i = 1; i <= 2; i++)
            {
                pingPongUpdaters[i].atmConfigToUse = atmosphereConfig;
                var t = pingPongUpdaters[i].UpdateCoroutine();
                while (t.MoveNext())
                {
                    ;
                }
            }
            UpdateSkyboxMaterial(pingPongUpdaters[1], pingPongUpdaters[2]);

            KickOffUpdater(pingPongUpdaters[0]);
        }
 public void UpdateSkyboxMaterial(ProgressiveLutUpdater updater, ProgressiveLutUpdater oldUpdater)
 {
     if (this.skyboxMaterial == null)
     {
         this.skyboxMaterial = new Material(Shader.Find("Skybox/AtmosphereScatteringPrecomputed"));
     }
     updater.atmConfigUsedToUpdate.Apply(skyboxMaterial);
     Shader.SetGlobalTexture("_SingleRayleigh_1", oldUpdater.singleRayleigh);
     Shader.SetGlobalTexture("_SingleMie_1", oldUpdater.singleMie);
     Shader.SetGlobalTexture("_SingleRayleigh_2", updater.singleRayleigh);
     Shader.SetGlobalTexture("_SingleMie_2", updater.singleMie);
     Shader.SetGlobalTexture("_MultipleScattering_1", oldUpdater.multiScatteringCombine);
     Shader.SetGlobalTexture("_MultipleScattering_2", updater.multiScatteringCombine);
     Shader.SetGlobalTexture("_Transmittance_1", oldUpdater.transmittance);
     Shader.SetGlobalTexture("_Transmittance_2", updater.transmittance);
     Shader.SetGlobalTexture("_GroundIrradiance_1", oldUpdater.groundIrradianceCombine);
     Shader.SetGlobalTexture("_GroundIrradiance_2", updater.groundIrradianceCombine);
     Shader.SetGlobalVector("_ScatteringSize", (Vector3)lutConfig.scatteringSize);
     Shader.SetGlobalVector("_GroundIrradianceSize", (Vector2)lutConfig.irradianceSize);
     Shader.SetGlobalVector("_TransmittanceSize", (Vector2)lutConfig.transmittanceSize);
     RenderSettings.skybox = this.skyboxMaterial;
 }
 private void KickOffUpdater(ProgressiveLutUpdater updater)
 {
     updater.atmConfigToUse = atmosphereConfig;
     StartCoroutine(updater.UpdateCoroutine());
 }