Beispiel #1
0
        public override void Update()
        {
            var delta = Engine.Get().Delta;

            _factorDay = _driverDay.Update(delta);

            _skyboxRotation = new Vector3(360.0f * _factorDay, 0.0f, 0.0f);

            var lightDirection = _skyboxRotation.Rotate(new Vector3(0.2f, 0.0f, 0.5f));

            lightDirection.Normalize();

            var fogColour = FogColourSunrise.Interpolate(FogColourNight, SunriseFactor);

            fogColour = fogColour.Interpolate(FogColourDay, ShadowFactor);

            _sunPosition  = lightDirection * new Vector3(-6048.0f, -6048.0f, -6048.0f);
            _moonPosition = lightDirection * new Vector3(6048.0f, 6048.0f, 6048.0f);

            /*if (Scenes.Get().GetCamera() != null)
             * {
             *  _sunPosition += Scenes.Get().Camera.Position;
             *  _moonPosition += Scenes.Get().Camera.Position;
             * }*/

            _sunColour = SunColourSunrise.Interpolate(SunColourNight, SunriseFactor);
            _sunColour = _sunColour.Interpolate(SunColourDay, ShadowFactor);

            _moonColour = MoonColourNight.Interpolate(MoonColourDay, ShadowFactor);

            _fog.Colour     = fogColour;
            _fog.Density    = 0.002f + ((1.0f - ShadowFactor * 0.002f));
            _fog.Gradient   = 2.0f - ((1.0f - ShadowFactor) * 0.380f);
            _fog.LowerLimit = 0.0f;
            _fog.UpperLimit = 0.15f - ((1.0f - ShadowFactor) * 0.03f);

            _skyColour = SkyboxColourDay;

            if (Shadows.Get() != null)
            {
                Shadows.Get().LightDirection    = lightDirection;
                Shadows.Get().ShadowBoxOffset   = (4.0f * (1.0f - ShadowFactor)) + 10.0f;
                Shadows.Get().ShadowBoxDistance = 40.0f;
                Shadows.Get().ShadowTransition  = 5.0f;
                Shadows.Get().ShadowDarkness    = 0.6f * ShadowFactor;
            }

            _factorSunrise = Math.Clamp(-((float)Math.Sin(2.0f * Math.PI * DayFactor) - 1.0f) / 2.0f, 0.0f, 1.0f);
            _factorShadow  = Math.Clamp(1.7f * (float)Math.Sin(2.0f * Math.PI * DayFactor), 0.0f, 1.0f);;
            _sunHeight     = _sunPosition.Y;
            _starIntensity = Math.Clamp(1.0f - ShadowFactor, 0.0f, 1.0f);
        }