public void Apply()
        {
            
            CelestialBody celestialBody = Tools.GetCelestialBody(body);
            if (celestialBody != null)
            {
                GameObject go = new GameObject();
                materialPQS = go.AddComponent<MaterialPQS>();
                macroMat = materialPQS.Apply(celestialBody, cityLightsMaterial, ShaderLoaderClass.FindShader("EVE/TerrainCityLight"), true, false);
                macroMat.name = materialName;
                macroMat.renderQueue = (int)Tools.Queue.Geometry + 1;
            }
            Transform transform = Tools.GetScaledTransform(body);
            if (transform != null)
            {
                Renderer r = transform.GetComponent<Renderer>();
                if (r != null)
                {
                    scaledMat = new Material(ShaderLoaderClass.FindShader("EVE/PlanetCityLight"));
                   
                    cityLightsMaterial.ApplyMaterialProperties(scaledMat);
                    scaledMat.SetTexture("_MainTex", r.material.GetTexture("_MainTex"));
                    scaledMat.name = materialName;
                    scaledMat.renderQueue = (int)Tools.Queue.Geometry + 1;
                    OverlayRenderer.Add(r.gameObject, scaledMat);

                    ScaledCityComponent sc = transform.gameObject.AddComponent<ScaledCityComponent>();
                    FieldInfo field = typeof(Sun).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).First(
                    f => f.Name == "scaledSunLight");
                    Light slight = (Light)field.GetValue(Sun.Instance);

                    sc.Apply(scaledMat, slight);
                }
            }

            
            LocalCityComponent lsc = FlightCamera.fetch.mainCamera.gameObject.AddComponent<LocalCityComponent>();
            Light light = Sun.Instance.GetComponent<Light>();
            lsc.Apply(macroMat, light);

            ApplyToMainMenu();

            GameEvents.onGameSceneLoadRequested.Add(SceneLoaded);
            if (HighLogic.LoadedScene == GameScenes.MAINMENU)
            {
                ApplyToMainMenu();
            }
        }
        public void Apply()
        {
            ShadowManager.Log("Applying to " + body);
            CelestialBody celestialBody = Tools.GetCelestialBody(body);
            
            Transform transform = Tools.GetScaledTransform(body);
            if (transform != null )
            {
                Renderer mr = transform.GetComponent<Renderer>();
                if (mr != null && hasSurface)
                {
                    shadowMat = new Material(ShadowShader);
                    GameObject go = new GameObject();
                    materialPQS = go.AddComponent<MaterialPQS>();
                    localShadowMat = materialPQS.Apply(celestialBody, null, ShadowShader, false, true);

                    //shadowMaterial.ApplyMaterialProperties(shadowMat);
                    shadowMat.SetFloat(ShaderProperties._SunRadius_PROPERTY, (float)(ScaledSpace.InverseScaleFactor * Sun.Instance.sun.Radius));
                    localShadowMat.SetFloat(ShaderProperties._SunRadius_PROPERTY, (float)(Sun.Instance.sun.Radius));

                    shadowMat.name = materialName;
                    localShadowMat.name = materialName;
                    shadowMat.renderQueue = (int)Tools.Queue.Geometry + 3;
                    localShadowMat.renderQueue = (int)Tools.Queue.Geometry + 3;
                    DeferredRenderer.Add(mr.gameObject, shadowMat);
                }
                
                ScaledShadowComponent sc = transform.gameObject.AddComponent<ScaledShadowComponent>();
                LocalShadowComponent lsc = FlightCamera.fetch.mainCamera.gameObject.AddComponent<LocalShadowComponent>();

                List<CelestialBody> casters = new List<CelestialBody>();
                if (caster != null)
                {
                    foreach (String b in caster)
                    {
                        casters.Add(Tools.GetCelestialBody(b));
                    }
                }
                sc.Apply(shadowMat, celestialBody, casters);
                lsc.Apply(localShadowMat, celestialBody, casters);
            }

            ApplyToMainMenu();

            GameEvents.onGameSceneLoadRequested.Add(SceneLoaded);
            if (HighLogic.LoadedScene == GameScenes.MAINMENU)
            {
                ApplyToMainMenu();
            }
        }