Beispiel #1
0
        public Material Apply(CelestialBody cb, MaterialManager mat, Shader shader, bool updateOrigin, bool subPQS)
        {
            KSPLog.print("Applying PQS Material Manager!");
            material = new Material(shader);
            if (mat != null)
            {
                mat.ApplyMaterialProperties(material);
            }


            this.updateOrigin = updateOrigin;
            this.subPQS       = subPQS;
            PQS pqs = null;

            body = cb;
            if (cb != null && cb.pqsController != null)
            {
                pqs = cb.pqsController;
            }
            else
            {
                KSPLog.print("No PQS!");
            }
            if (pqs != null)
            {
                this.sphere           = pqs;
                this.transform.parent = pqs.transform;
                this.requirements     = PQS.ModiferRequirements.Default;
                this.modEnabled       = true;
                this.order           += 10;

                this.transform.localPosition = Vector3.zero;
                this.transform.localRotation = Quaternion.identity;
                this.transform.localScale    = Vector3.one;
            }

            if (this.sphere != null && this.sphere.quads != null)
            {
                foreach (PQ pq in this.sphere.quads)
                {
                    ApplyToQuadMaterials(pq);
                }
            }

            if (subPQS && this.sphere != null && this.sphere.ChildSpheres != null && this.sphere.ChildSpheres.Length > 0)
            {
                GameObject  go       = new GameObject();
                MaterialPQS ChildPQS = go.AddComponent <MaterialPQS>();
                ChildPQS.updateOrigin = false;
                ChildPQS.subPQS       = false;
                ChildPQS.isOcean      = true;

                pqs = this.sphere.ChildSpheres[0];
                if (pqs != null)
                {
                    ChildPQS.sphere           = pqs;
                    ChildPQS.transform.parent = pqs.transform;
                    ChildPQS.requirements     = PQS.ModiferRequirements.Default;
                    ChildPQS.modEnabled       = true;
                    ChildPQS.order           += 10;

                    ChildPQS.transform.localPosition = Vector3.zero;
                    ChildPQS.transform.localRotation = Quaternion.identity;
                    ChildPQS.transform.localScale    = Vector3.one;
                    ChildPQS.material = material;
                }

                if (ChildPQS.sphere != null && ChildPQS.sphere.quads != null)
                {
                    foreach (PQ pq in this.sphere.quads)
                    {
                        ApplyToQuadMaterials(pq);
                    }
                }
            }
            GameEvents.OnPQSCityLoaded.Add(PQSLoaded);

            return(material);
        }
        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();
            }
        }