Example #1
0
        void Start()
        {
            defaultFog        = RenderSettings.fogColor;
            nightFog          = new Color(defaultFog.r * 0.05f, defaultFog.g * 0.05f, defaultFog.b * 0.05f, 1f);
            defaultFogDensity = RenderSettings.fogDensity;

            CloudMaterial.SetFloat("_CloudSpeed", 0.03f);
            StarMaterial.SetFloat("_Exposure", 2.0f);

            WeatherSource.CurrentWeatherState  = WeatherState.LoadFromXML(WeatherSource.XMLWeatherStatePath + "PSWS_FALLBACK");
            WeatherSource.NextWeatherState     = null;
            WeatherSource.WeatherStateBlending = 0;

            StartCoroutine(WeatherSource.WeatherStateChanger());
            StartCoroutine(WeatherSource.UpdateCloudRenderTex());
            StartCoroutine(ReflectionProbeUpdater.UpdateProbe());
        }
Example #2
0
        void Update()
        {
            if (Main.settings.cloudShadowsEnabled)
            {
                SunLight.cookie = WeatherSource.SunShadowRenderImage;
            }
            else
            {
                SunLight.cookie = null;
            }

#if !CYBEX_TIME
            // fauxnik time algo
            ProceduralSkyTimeSource.Instance.CalculateTimeProgress(Time.deltaTime);
            var currentTime = TimeSourceAdapter.GetCurrentTime();
#if DEBUG
            DevGUI devGui = GetComponent <DevGUI>();
            if (devGui != null && devGui.dateTimeOverride)
            {
                currentTime = devGui.CurrentTime;
            }
#endif

            DateToSkyMapper.ApplyDate(currentTime);

            // daily & yearly rotation of skybox night
            SkyboxNight.localRotation = DateToSkyMapper.SkyboxNightRotation;

            // daily & seasonal rotation of the sun
            SunPathCenter.parent.localRotation = DateToSkyMapper.SunPivotRotation;
            SunPathCenter.localPosition        = DateToSkyMapper.SunOffsetFromPath;

            // daily & seasonal rotation of the moon
            MoonPathCenter.parent.localRotation = DateToSkyMapper.MoonPivotRotation;
            MoonPathCenter.localPosition        = DateToSkyMapper.MoonOffsetFromPath;
#else
            // cybex time algo
            CybexTime.CalculateTimeProgress(Main.settings.latitude, 0);

            // rotations
            SkyboxNight.localRotation           = Quaternion.Euler(CybexTime.SkyboxNightRotation);
            SunPathCenter.parent.localRotation  = Quaternion.Euler(CybexTime.SunPivotRotation);
            MoonPathCenter.parent.localRotation = Quaternion.Euler(CybexTime.MoonRotation);

#if DEBUG
            // TODO: update this
            DevGUI devGui = GetComponent <DevGUI>();
            if (devGui != null && devGui.posOverride)
            {
                devGui.CalculateRotationOverride();
                SkyboxNight.localRotation    = devGui.skyRot;
                SunPathCenter.localRotation  = devGui.sunRot;
                MoonPathCenter.localRotation = devGui.moonRot;
            }
#endif
#endif

            // movement
            worldPos           = PlayerManager.PlayerTransform.position - WorldMover.currentMove;
            transform.position = new Vector3(worldPos.x * .001f, 0, worldPos.z * .001f);

            Vector3 highLatitudeCorrection = SunPathCenter.parent.TransformVector(SunPathCenter.localPosition) - SunPathCenter.parent.position / DateToSkyMapper.maxProjectedSunOffset;
            Vector3 sunPos            = SunLight.transform.position - SunPathCenter.position + highLatitudeCorrection;
            float   sunOverHorizonFac = Mathf.Clamp01(sunPos.y);
            SunLight.intensity = sunOverHorizonFac * 1.5f;
            SunLight.color     = Color.Lerp(new Color(1f, 0.5f, 0), Color.white, sunOverHorizonFac);

            StarMaterial.SetFloat("_Visibility", (-sunOverHorizonFac + 1) * .01f);

            MoonMaterial.SetFloat("_MoonDayNight", Mathf.Lerp(2.19f, 1.5f, sunOverHorizonFac));
            // gives aproximate moon phase
            MoonMaterial.SetFloat("_MoonPhase", Vector3.SignedAngle(SunPathCenter.right, MoonPathCenter.right, SunPathCenter.forward) / 180);
            MoonMaterial.SetFloat("_Exposure", Mathf.Lerp(2f, 4f, sunOverHorizonFac));

            SkyMaterial.SetFloat("_Exposure", Mathf.Lerp(.01f, 1f, sunOverHorizonFac));
            SkyMaterial.SetFloat("_AtmosphereThickness", Mathf.Lerp(0.1f, 1f, Mathf.Clamp01(sunOverHorizonFac * 10)));

            CloudMaterial.SetFloat("_NScale", WeatherSource.CloudNoiseScaleBlend);
            CloudMaterial.SetFloat("_ClearSky", WeatherSource.CloudClearSkyBlend);
            float facC = Mathf.Lerp(.002f, 1f, sunOverHorizonFac);
            CloudMaterial.SetFloat("_CloudBright", WeatherSource.CloudBrightnessBlend * facC);
            float facG = Mathf.Lerp(.25f, 0.0f, sunOverHorizonFac);
            CloudMaterial.SetFloat("_CloudGradient", WeatherSource.CloudGradientBlend + facG);
            CloudMaterial.SetFloat("_CloudSpeed", WeatherSource.CloudSpeedBlend);
            CloudMaterial.SetFloat("_CloudChange", WeatherSource.CloudChangeBlend);
#if DEBUG
            if (devGui != null && devGui.cloudOverride)
            {
                CloudMaterial.SetFloat("_NScale", devGui.loadedWeatherState.cloudNoiseScale);
                CloudMaterial.SetFloat("_ClearSky", devGui.loadedWeatherState.cloudClearSky);
                CloudMaterial.SetFloat("_CloudBright", devGui.loadedWeatherState.cloudBrightness * facC);
                CloudMaterial.SetFloat("_CloudGradient", devGui.loadedWeatherState.cloudGradient + facG);
                CloudMaterial.SetFloat("_CloudSpeed", devGui.loadedWeatherState.cloudSpeed);
                CloudMaterial.SetFloat("_CloudChange", devGui.loadedWeatherState.cloudChange);
            }
#endif

            RenderSettings.fogColor        = Color.Lerp(nightFog, defaultFog, sunOverHorizonFac);
            RenderSettings.ambientSkyColor = Color.Lerp(ambientNight, ambientDay, sunOverHorizonFac);

#if DEBUG
            if (devGui != null && devGui.rainOverride)
            {
                RenderSettings.fogDensity = Mathf.Lerp(defaultFogDensity, defaultFogDensity * 3, devGui.loadedWeatherState.rainParticleStrength);
                RainController.SetRainStrength(devGui.loadedWeatherState.rainParticleStrength);
            }
            else
            {
                RenderSettings.fogDensity = Mathf.Lerp(defaultFogDensity, defaultFogDensity * 3, WeatherSource.RainStrengthBlend);
                RainController.SetRainStrength(WeatherSource.RainStrengthBlend);
            }
#else
            RenderSettings.fogDensity = Mathf.Lerp(defaultFogDensity, defaultFogDensity * 3, WeatherSource.RainStrengthBlend);
            RainController.SetRainStrength(WeatherSource.RainStrengthBlend);
#endif

            RainController.SetRainColor(new Color(RenderSettings.fogColor.r + 0.5f, RenderSettings.fogColor.g + 0.5f, RenderSettings.fogColor.b + 0.5f, 1));
        }