Esempio n. 1
0
 public WeatherState(string fileName, WeatherState copyState)
 {
     this.fileName             = fileName;
     this.name                 = copyState.name;
     this.cloudClearSky        = copyState.cloudClearSky;
     this.cloudNoiseScale      = copyState.cloudNoiseScale;
     this.cloudChange          = copyState.cloudChange;
     this.cloudSpeed           = copyState.cloudSpeed;
     this.cloudBrightness      = copyState.cloudBrightness;
     this.cloudGradient        = copyState.cloudGradient;
     this.rainParticleStrength = copyState.rainParticleStrength;
 }
Esempio n. 2
0
        private static WeatherState GetFALLBACK()
        {
            if (File.Exists(WeatherSource.XMLWeatherStatePath + "PSWS_FALLBACK"))
            {
                Debug.Log(">>> >>> >>> Get FALLBACK From File");
                return(LoadFromXML(WeatherSource.XMLWeatherStatePath + "PSWS_FALLBACK"));
            }
            WeatherState fallback = new WeatherState("PSWS_FALLBACK", "FALLBACK", 0, 1, 0.1f, 0.001f, 0, 0, 1);

            CreateNewXML(fallback);
            Debug.Log(">>> >>> >>> Created New FALLBACK File");
            return(fallback);
        }
Esempio n. 3
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());
        }
Esempio n. 4
0
        public void Init()
        {
#if DEBUG
            Debug.Log(">>> >>> >>> Cybex_ProceduralSkyMod : Initializer Starting Setup...");
            Debug.Log(">>> >>> >>> Loading Asset Bundle...");
#endif
            // Load the asset bundle
            AssetBundle assets = AssetBundle.LoadFromFile(Main.ModPath + "Resources/proceduralskymod");

            _skyMaterial   = assets.LoadAsset <Material>("Assets/Materials/Sky.mat");
            _rainAudioClip = assets.LoadAsset <AudioClip>("Assets/Audio/rain-03.wav");
            _cloudPrefab   = assets.LoadAsset <GameObject>("Assets/Prefabs/CloudPlane.prefab");
            _starMaterial  = assets.LoadAsset <Material>("Assets/Materials/StarBox.mat");
            _moonPrefab    = assets.LoadAsset <GameObject>("Assets/Prefabs/Moon.prefab");
            _rainPrefab    = assets.LoadAsset <GameObject>("Assets/Prefabs/RainDrop.prefab");

            assets.Unload(false);

#if DEBUG
            Debug.Log(">>> >>> >>> Loading Saved State...");
#endif
            SkySaveManager.Load();
            ProceduralSkyTimeSource.LoadSavedTime();

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Skybox Material...");
#endif
            // Set skybox material
            Material skyMaterial = _skyMaterial;

            skyMaterial.SetColor("_SkyTint", new Color(0.3f, 0.3f, 0.8f, 1f));
            skyMaterial.SetColor("_GroundColor", new Color(0.369f, 0.349f, 0.341f, 1f));

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Procedural Sky Master...");
#endif
            // Setup dynamic sky
            GameObject psMaster = new GameObject()
            {
                name = "ProceduralSkyMod"
            };
            psMaster.transform.Reset();
            SkyManager skyManager = psMaster.AddComponent <SkyManager>();

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Directional Light...");
#endif
            // Find directional light and setup
            GameObject[] roots = SceneManager.GetActiveScene().GetRootGameObjects();
            for (int i = 0; i < roots.Length; i++)
            {
                if (roots[i].name == "Directional Light")
                {
                    roots[i].SetActive(false);
                }
            }

            dirLight = new GameObject()
            {
                name = "Sun"
            }.AddComponent <Light>();

            dirLight.type           = LightType.Directional;
            dirLight.shadows        = LightShadows.Soft;
            dirLight.shadowStrength = 0.9f;
            dirLight.gameObject.AddComponent <LookAtConstraintOnPreCull>().target = psMaster.transform;
            dirLight.cookieSize = 2000;

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Cameras...");
#endif
            // main cam
            mainCam              = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
            mainCam.clearFlags   = CameraClearFlags.Depth;
            mainCam.cullingMask  = -1;
            mainCam.cullingMask &= ~(1 << 31);
            //mainCam.depth = -1; // original setting

            // sky cam
            Camera skyCam = new GameObject()
            {
                name = "SkyCam"
            }.AddComponent <Camera>();
            GameObject skyCamGimbal = new GameObject {
                name = "SkyCamGimbal"
            };
            skyCamGimbal.transform.SetParent(psMaster.transform, false);
            skyCam.transform.SetParent(skyCamGimbal.transform, false);
            skyCam.clearFlags    = CameraClearFlags.Depth;
            skyCam.cullingMask   = 0;
            skyCam.cullingMask  |= 1 << 31;
            skyCam.depth         = -2;
            skyCam.fieldOfView   = mainCam.fieldOfView;
            skyCam.nearClipPlane = mainCam.nearClipPlane;
            skyCam.farClipPlane  = 100;
            // this localScale negates VR stereo separation
            skyCamGimbal.transform.localScale = Vector3.zero;
            skyCamGimbal.AddComponent <PositionConstraintOnPreCull>().source = psMaster.transform;

            // clear cam
            Camera clearCam = new GameObject()
            {
                name = "ClearCam"
            }.AddComponent <Camera>();
            clearCam.clearFlags  = CameraClearFlags.Skybox;
            clearCam.cullingMask = 0;
            clearCam.depth       = -3;
            clearCam.fieldOfView = mainCam.fieldOfView;

            SkyCamConstraint constraint = skyCam.gameObject.AddComponent <SkyCamConstraint>();
            constraint.main  = mainCam;
            constraint.sky   = skyCam;
            constraint.clear = clearCam;

            // cloud render texture cam
            Camera cloudRendTexCam = new GameObject()
            {
                name = "CloudRendTexCam"
            }.AddComponent <Camera>();
            cloudRendTexCam.transform.SetParent(psMaster.transform);
            cloudRendTexCam.transform.ResetLocal();
            cloudRendTexCam.transform.localPosition = new Vector3(0, 3, 0);
            cloudRendTexCam.transform.localRotation = Quaternion.Euler(new Vector3(90, 0, 0));
            cloudRendTexCam.clearFlags             = CameraClearFlags.Color;
            cloudRendTexCam.backgroundColor        = Color.clear;
            cloudRendTexCam.cullingMask            = 0;
            cloudRendTexCam.cullingMask           |= 1 << 31;
            cloudRendTexCam.orthographic           = true;
            cloudRendTexCam.orthographicSize       = 3;
            cloudRendTexCam.nearClipPlane          = 0;
            cloudRendTexCam.farClipPlane           = 3;
            cloudRendTexCam.renderingPath          = RenderingPath.Forward;
            cloudRendTexCam.targetTexture          = WeatherSource.CloudRenderTex;
            cloudRendTexCam.useOcclusionCulling    = false;
            cloudRendTexCam.allowHDR               = false;
            cloudRendTexCam.allowMSAA              = false;
            cloudRendTexCam.allowDynamicResolution = false;
            cloudRendTexCam.forceIntoRenderTexture = true;
            WeatherSource.CloudRenderTexCam        = cloudRendTexCam;
            cloudRendTexCam.enabled = false;             // disable the camera, renders will be triggered by script

            // sun shadow render texture cam
            Camera sunShadowRendTexCam = new GameObject()
            {
                name = "SunShadowRendTextCam"
            }.AddComponent <Camera>();
            sunShadowRendTexCam.transform.SetParent(dirLight.transform);
            sunShadowRendTexCam.transform.ResetLocal();

            sunShadowRendTexCam.clearFlags      = CameraClearFlags.Color;
            sunShadowRendTexCam.backgroundColor = Color.clear;
            sunShadowRendTexCam.cullingMask     = 0;
            sunShadowRendTexCam.cullingMask    |= 1 << 31;

            //sunShadowRendTexCam.fieldOfView = dirLight.spotAngle;
            sunShadowRendTexCam.orthographic     = true;
            sunShadowRendTexCam.orthographicSize = 2;
            sunShadowRendTexCam.nearClipPlane    = 0;
            sunShadowRendTexCam.farClipPlane     = 100;

            sunShadowRendTexCam.renderingPath          = RenderingPath.Forward;
            sunShadowRendTexCam.targetTexture          = WeatherSource.SunShadowRenderTex;
            sunShadowRendTexCam.useOcclusionCulling    = false;
            sunShadowRendTexCam.allowHDR               = false;
            sunShadowRendTexCam.allowMSAA              = false;
            sunShadowRendTexCam.allowDynamicResolution = false;
            sunShadowRendTexCam.forceIntoRenderTexture = true;
            WeatherSource.SunShadowRenderTexCam        = sunShadowRendTexCam;
            sunShadowRendTexCam.enabled = false;             // disable the camera, renders will be triggered by script

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Audio Sources...");
#endif
            GameObject psAudio = new GameObject()
            {
                name = "ProceduralSkyAudio"
            };
            psAudio.transform.SetParent(mainCam.transform);
            RainController.RainAudio = psAudio.AddComponent <AudioSource>();

            RainController.RainAudio.clip                  = _rainAudioClip;
            RainController.RainAudio.mute                  = false;
            RainController.RainAudio.bypassEffects         = false;
            RainController.RainAudio.bypassListenerEffects = false;
            RainController.RainAudio.bypassReverbZones     = false;
            RainController.RainAudio.playOnAwake           = true;
            RainController.RainAudio.loop                  = true;
            RainController.RainAudio.priority              = 128;
            RainController.RainAudio.volume                = 0; // always ramp up from 0 when the game loads

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Cloud Plane...");
#endif
            GameObject cloudPlane = new GameObject();

            MeshFilter filter = cloudPlane.AddComponent <MeshFilter>();
            filter.sharedMesh = _cloudPrefab.GetComponent <MeshFilter>().sharedMesh;
            MeshRenderer renderer = cloudPlane.AddComponent <MeshRenderer>();
            Material     cloudMat = renderer.sharedMaterial = _cloudPrefab.GetComponent <MeshRenderer>().sharedMaterial;

            cloudPlane.transform.SetParent(psMaster.transform);
            cloudPlane.transform.ResetLocal();
            cloudPlane.layer = 31;

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Skybox Night...");
#endif
            GameObject skyboxNight = new GameObject()
            {
                name = "SkyboxNight"
            };
            skyboxNight.transform.SetParent(psMaster.transform);
            skyboxNight.transform.ResetLocal();

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Sun Position...");
#endif
            GameObject sunPivot = new GameObject()
            {
                name = "SunPivot"
            };
            GameObject sunSlider = new GameObject()
            {
                name = "SunSlider"
            };                                                                          // sunSlider mimics moonBillboards in-built mesh offset
            sunPivot.transform.SetParent(psMaster.transform, false);
            sunSlider.transform.SetParent(sunPivot.transform, false);
            dirLight.transform.SetParent(sunSlider.transform, false);
            dirLight.transform.position     += Vector3.up * sunDistanceToCamera;
            dirLight.transform.localRotation = Quaternion.Euler(new Vector3(90, 0, 0));

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Starbox...");
#endif
            GameObject starBox = GameObject.CreatePrimitive(PrimitiveType.Cube);
            starBox.GetComponent <MeshRenderer>().sharedMaterial = _starMaterial;
            starBox.transform.SetParent(skyboxNight.transform);
            starBox.transform.ResetLocal();
            starBox.transform.localRotation = Quaternion.Euler(new Vector3(0, 68.5f, 28.9f));
            starBox.transform.localScale    = Vector3.one * 20;
            starBox.layer = 31;

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Moon Billboard...");
#endif
            GameObject moonBillboard = new GameObject()
            {
                name = "MoonBillboard"
            };
            GameObject moonPivot = new GameObject()
            {
                name = "MoonPivot"
            };

            filter                  = moonBillboard.AddComponent <MeshFilter>();
            filter.sharedMesh       = _moonPrefab.GetComponent <MeshFilter>().sharedMesh;
            renderer                = moonBillboard.AddComponent <MeshRenderer>();
            renderer.sharedMaterial = _moonPrefab.GetComponent <MeshRenderer>().sharedMaterial;

            moonPivot.transform.SetParent(psMaster.transform, false);
            moonBillboard.transform.SetParent(moonPivot.transform, false);
            moonBillboard.transform.localScale = Vector3.one * moonDistanceToCamera / 2;             // moonBillboard mesh has in-built offset of 2
            moonBillboard.layer = 31;

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Rain Particle System...");
#endif
            GameObject psRainParticleSys = new GameObject()
            {
                name = "ProceduralSkyRainParticleSystem"
            };

            PositionConstraintOnUpdate psRainParticleSysconstraint = psRainParticleSys.AddComponent <PositionConstraintOnUpdate>();
            psRainParticleSysconstraint.source = mainCam.transform;

            GameObject rainObj = GameObject.Instantiate(_rainPrefab);
            rainObj.transform.SetParent(psRainParticleSys.transform);
            rainObj.transform.ResetLocal();
            rainObj.transform.Translate(Vector3.up * 16);

            RainController.SetRainParticleSystemArray(psRainParticleSys.GetComponentsInChildren <ParticleSystem>(true));
            WeatherSource.CloudRenderEvent += RainController.SetShapeTextures;

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Weather Source...");
#endif
            WeatherSource.CurrentWeatherState = WeatherState.LoadFromXML(WeatherSource.XMLWeatherStatePath + SkySaveManager.State.currentWeatherState);
            if (!string.IsNullOrEmpty(SkySaveManager.State.nextWeatherState))
            {
                WeatherSource.NextWeatherState = WeatherState.LoadFromXML(WeatherSource.XMLWeatherStatePath + SkySaveManager.State.nextWeatherState);
            }
            WeatherSource.WeatherStateBlending = SkySaveManager.State.weatherStateBlending;

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Sky Manager Properties...");
#endif
            // assign skyboxNight after sun is positioned to get correct sun rotation
            skyManager.SkyboxNight   = skyboxNight.transform;
            skyManager.SunPathCenter = sunSlider.transform;
            skyManager.SunLight      = dirLight;

            skyManager.CloudPlane    = cloudPlane.transform;
            skyManager.CloudMaterial = cloudMat;

            skyManager.StarMaterial = starBox.GetComponent <MeshRenderer>().sharedMaterial;

            skyManager.SkyCam      = skyCam.transform;
            skyManager.SkyMaterial = skyMaterial;

            skyManager.ClearCam = clearCam.transform;

            skyManager.MoonPathCenter = moonBillboard.transform;
            skyManager.MoonMaterial   = moonBillboard.GetComponent <MeshRenderer>().sharedMaterial;

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Render Settings...");
#endif
            // Set render settings
            RenderSettings.sun         = dirLight;
            RenderSettings.skybox      = skyMaterial;
            RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Sky Save...");
#endif
            DV.AppUtil.GamePaused += SkySaveManager.Save;

#if DEBUG
            Debug.Log(">>> >>> >>> Setting Up Reflection Probe Updater...");
#endif
            ReflectionProbeUpdater.probe = FindObjectOfType <DynamicReflectionProbe>().GetComponent <ReflectionProbe>();

#if DEBUG
            psMaster.AddComponent <DevGUI>();
            Debug.Log(">>> >>> >>> Cybex_ProceduralSkyMod : Initializer Finished Setup...");
#endif
            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
            go.transform.ResetLocal();
            go.transform.position   += Vector3.up * 130;
            go.transform.localScale *= 10;
        }
Esempio n. 5
0
        public static WeatherState LoadFromXML(string filePath)
        {
            try
            {
                WeatherState state = new WeatherState();
                XmlDocument  doc   = new XmlDocument();
                doc.Load(filePath);
                foreach (XmlNode nodes0 in doc.DocumentElement)
                {
                    foreach (XmlNode nodes1 in nodes0.ChildNodes)
                    {
                        switch (nodes0.Name)
                        {
                        case "Names":
                            if (nodes1.Name == "fileName")
                            {
                                state.fileName = nodes1.InnerText;
                            }
                            if (nodes1.Name == "name")
                            {
                                state.name = nodes1.InnerText;
                            }
                            break;

                        case "Clouds":
                            if (nodes1.Name == "cloudClearSky")
                            {
                                state.cloudClearSky = float.Parse(nodes1.InnerText);
                            }
                            if (nodes1.Name == "cloudNoiseScale")
                            {
                                state.cloudNoiseScale = float.Parse(nodes1.InnerText);
                            }
                            if (nodes1.Name == "cloudChange")
                            {
                                state.cloudChange = float.Parse(nodes1.InnerText);
                            }
                            if (nodes1.Name == "cloudSpeed")
                            {
                                state.cloudSpeed = float.Parse(nodes1.InnerText);
                            }
                            if (nodes1.Name == "cloudBrightness")
                            {
                                state.cloudBrightness = float.Parse(nodes1.InnerText);
                            }
                            if (nodes1.Name == "cloudGradient")
                            {
                                state.cloudGradient = float.Parse(nodes1.InnerText);
                            }
                            break;

                        case "Rain":
                            if (nodes1.Name == "rainParticleStrength")
                            {
                                state.rainParticleStrength = float.Parse(nodes1.InnerText);
                            }
                            break;

                        default:
                            Debug.LogWarning("FOO");
                            break;
                        }
                    }
                }
                return(state);
            }
            catch
            {
                Debug.LogWarning($"WeatherState.cs: Load From XML Error While Trying To Load\n{filePath}");
                return(GetFALLBACK());
            }
        }
Esempio n. 6
0
        private static void CreateNewXML(WeatherState state)
#endif
        {
            XmlDocument doc      = new XmlDocument();
            XmlNode     rootNode = doc.CreateElement("WeatherState");

            doc.AppendChild(rootNode);

            // name data
            XmlNode namesNode = doc.CreateElement("Names");

            rootNode.AppendChild(namesNode);

            XmlNode filenameNode = doc.CreateElement("fileName");

            filenameNode.InnerText = state.fileName;
            namesNode.AppendChild(filenameNode);

            XmlNode nameNode = doc.CreateElement("name");

            nameNode.InnerText = state.name;
            namesNode.AppendChild(nameNode);

            // cloud data
            XmlNode cloudsNode = doc.CreateElement("Clouds");

            rootNode.AppendChild(cloudsNode);

            XmlNode cloudClearSky = doc.CreateElement("cloudClearSky");

            cloudClearSky.InnerText = state.cloudClearSky.ToString();
            cloudsNode.AppendChild(cloudClearSky);

            XmlNode cloudNoiseScale = doc.CreateElement("cloudNoiseScale");

            cloudNoiseScale.InnerText = state.cloudNoiseScale.ToString();
            cloudsNode.AppendChild(cloudNoiseScale);

            XmlNode cloudChange = doc.CreateElement("cloudChange");

            cloudChange.InnerText = state.cloudChange.ToString();
            cloudsNode.AppendChild(cloudChange);

            XmlNode cloudSpeed = doc.CreateElement("cloudSpeed");

            cloudSpeed.InnerText = state.cloudSpeed.ToString();
            cloudsNode.AppendChild(cloudSpeed);

            XmlNode cloudBrightness = doc.CreateElement("cloudBrightness");

            cloudBrightness.InnerText = state.cloudBrightness.ToString();
            cloudsNode.AppendChild(cloudBrightness);

            XmlNode cloudGradient = doc.CreateElement("cloudGradient");

            cloudGradient.InnerText = state.cloudGradient.ToString();
            cloudsNode.AppendChild(cloudGradient);

            // rain data
            XmlNode rainNode = doc.CreateElement("Rain");

            rootNode.AppendChild(rainNode);

            XmlNode rainParticleStrength = doc.CreateElement("rainParticleStrength");

            rainParticleStrength.InnerText = state.rainParticleStrength.ToString();
            rainNode.AppendChild(rainParticleStrength);

            doc.Save(WeatherSource.XMLWeatherStatePath + state.fileName);
        }
Esempio n. 7
0
 public static void CreateNewXML(WeatherState state)