Esempio n. 1
0
            /// <summary>
            /// Updates this instance
            /// </summary>
            void LateUpdate()
            {
                // Apply light settings
                shifter.Apply(light, scaledSunLight, iva?.GetComponent <Light>());

                // Set SunFlare color
                sunFlare.color = shifter.sunLensFlareColor;

                // Set other stuff
                AU = shifter.AU;
                brightnessCurve = shifter.brightnessCurve.Curve;

                // Update the lensflare orientation and scale
                sunFlare.brightness = brightnessMultiplier * brightnessCurve.Evaluate((float)(1 / (Vector3d.Distance(target.position, ScaledSpace.LocalToScaledSpace(sun.position)) / (AU * ScaledSpace.InverseScaleFactor))));

                // States
                bool lightsOn = (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneHasPlanetarium || HighLogic.LoadedScene == GameScenes.SPACECENTER);

                light.enabled    = shifter.givesOffLight && lightsOn && Current == this;
                sunFlare.enabled = shifter.givesOffLight && lightsOn;
                if (useLocalSpaceSunLight && Sun.Instance.useLocalSpaceSunLight)
                {
                    scaledSunLight.enabled = shifter.givesOffLight && lightsOn && Current == this;
                }

                // Update Scaled Space Light
                if (!useLocalSpaceSunLight)
                {
                    return;
                }
                Vector3d localSpace = ScaledSpace.ScaledToLocalSpace(target.position);

                if (FlightGlobals.currentMainBody == null || FlightGlobals.currentMainBody == sun)
                {
                    localTime       = 1f;
                    light.intensity = scaledSunLight.intensity;
                }
                else
                {
                    double targetAltitude = FlightGlobals.getAltitudeAtPos(localSpace, FlightGlobals.currentMainBody);
                    if (targetAltitude < 0)
                    {
                        targetAltitude = 0;
                    }
                    double horizonAngle   = Math.Acos(FlightGlobals.currentMainBody.Radius / (FlightGlobals.currentMainBody.Radius + targetAltitude));
                    float  horizonScalar  = -Mathf.Sin((float)horizonAngle);
                    float  dayNightRatio  = 1f - Mathf.Abs(horizonScalar);
                    float  fadeStartAtAlt = horizonScalar + fadeStart * dayNightRatio;
                    float  fadeEndAtAlt   = horizonScalar - fadeEnd * dayNightRatio;
                    localTime       = Vector3.Dot(-FlightGlobals.getUpAxis(localSpace), transform.forward);
                    light.intensity = Mathf.Lerp(0f, scaledSunLight.intensity, Mathf.InverseLerp(fadeEndAtAlt, fadeStartAtAlt, localTime));
                }
            }
Esempio n. 2
0
            /// <summary>
            /// Updates this instance
            /// </summary>
            void LateUpdate()
            {
                // Set precision
                sunRotationPrecision = MapView.MapIsEnabled ? sunRotationPrecisionMapView : sunRotationPrecisionDefault;

                // Apply light settings
                Vector3d localSpace = ScaledSpace.ScaledToLocalSpace(target.position);

                if (light)
                {
                    light.color     = shifter.sunlightColor;
                    light.intensity =
                        shifter.intensityCurve.Evaluate((Single)Vector3d.Distance(sun.position, localSpace));
                    light.shadowStrength = shifter.sunlightShadowStrength;
                }

                // Patch the ScaledSpace light
                if (scaledSunLight)
                {
                    scaledSunLight.color     = shifter.scaledSunlightColor;
                    scaledSunLight.intensity = shifter.scaledIntensityCurve.Evaluate((Single)Vector3d.Distance(ScaledSpace.LocalToScaledSpace(sun.position), target.position));
                }

                if (HighLogic.LoadedSceneIsFlight && iva?.GetComponent <Light>())
                {
                    iva.GetComponent <Light>().color     = shifter.IVASunColor;
                    iva.GetComponent <Light>().intensity = shifter.ivaIntensityCurve.Evaluate((Single)Vector3d.Distance(sun.position, localSpace));
                }

                // Set SunFlare color
                lensFlare.sunFlare.color = shifter.sunLensFlareColor;

                // Set other stuff
                lensFlare.AU = shifter.AU;
                lensFlare.brightnessCurve = shifter.brightnessCurve.Curve;
                lensFlare.sun             = sun;
                lensFlare.target          = target;

                // States
                Boolean lightsOn = (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneHasPlanetarium || HighLogic.LoadedScene == GameScenes.SPACECENTER);

                light.enabled = shifter.givesOffLight && lightsOn;
                lensFlare.sunFlare.enabled = shifter.givesOffLight && lightsOn;
                sunFlare.enabled           = false;
                if (useLocalSpaceSunLight && Sun.Instance.useLocalSpaceSunLight)
                {
                    scaledSunLight.enabled = shifter.givesOffLight && lightsOn;
                }
                if (Current != null && Current.lensFlare != null)
                {
                    SunFlare.Instance = Current.lensFlare;
                }

                // Update Scaled Space Light
                if (!useLocalSpaceSunLight)
                {
                    return;
                }
                if (FlightGlobals.currentMainBody == null || FlightGlobals.currentMainBody == sun)
                {
                    localTime = 1f;
                }
                else
                {
                    Double targetAltitude = FlightGlobals.getAltitudeAtPos(localSpace, FlightGlobals.currentMainBody);
                    if (targetAltitude < 0)
                    {
                        targetAltitude = 0;
                    }
                    Double horizonAngle   = Math.Acos(FlightGlobals.currentMainBody.Radius / (FlightGlobals.currentMainBody.Radius + targetAltitude));
                    Single horizonScalar  = -Mathf.Sin((Single)horizonAngle);
                    Single dayNightRatio  = 1f - Mathf.Abs(horizonScalar);
                    Single fadeStartAtAlt = horizonScalar + fadeStart * dayNightRatio;
                    Single fadeEndAtAlt   = horizonScalar - fadeEnd * dayNightRatio;
                    localTime       = Vector3.Dot(-FlightGlobals.getUpAxis(localSpace), transform.forward);
                    light.intensity = Mathf.Lerp(0f, light.intensity, Mathf.InverseLerp(fadeEndAtAlt, fadeStartAtAlt, localTime));
                }
            }