// Update is called once per frame void Update() { #if UNITY_EDITOR int stage = GameObjectTypeLoggingSM.postStageInformation(this.gameObject); if (stage == 4) { Debug.Log("Grass is in prefab edit mode"); return; } #endif //configure and close if (configure && !configured && SkyManager != null) { #if UNITY_EDITOR LayerMaskCreateSM.CreateLayer("Background"); LayerMaskCreateSM.CreateLayer("Conductor"); #endif if (Camera.main == null) { //add main camera GameObject cameraMain = new GameObject(); cameraMain.tag = "MainCamera"; cameraMain.AddComponent <Camera>(); } if (Camera.main != null) { //v4.8.4 Camera.main.farClipPlane = 30000; Camera.main.transform.position = Camera.main.transform.position + new Vector3(0, 10, 0); SkyManager.Current_Time = 10.3f; //ADD CLOUDS FullVolumeCloudsSkyMaster cloudsScript = Camera.main.gameObject.GetComponent <FullVolumeCloudsSkyMaster>(); if (cloudsScript != null) { cloudsScript.Sun = SkyManager.SunObj.transform; cloudsScript.SkyManager = SkyManager; cloudsScript.initVariablesScatter(); SkyManager.volumeClouds = cloudsScript; } else { cloudsScript = Camera.main.gameObject.AddComponent <FullVolumeCloudsSkyMaster>(); cloudsScript.Sun = SkyManager.SunObj.transform; cloudsScript.SkyManager = SkyManager; cloudsScript.initVariablesA(); cloudsScript.initVariablesScatter(); SkyManager.volumeClouds = cloudsScript; } //Use Temporal AA to lower cloud raycast steps if (Camera.main.gameObject.GetComponent <TemporalReprojection>() == null) { Camera.main.gameObject.AddComponent <TemporalReprojection>(); } //ADD REFLECTIONS if water active FullVolumeCloudsSkyMaster CloudsScript = SkyManager.volumeClouds; int layerToCheck = LayerMask.NameToLayer("Background"); if (CloudsScript != null) { if (SkyManager.water != null) { //v4.8.5 if (CloudsScript.reflectClouds == null) //v4.8.5 { //WATER enable if (enableWater) { SkyManager.water.transform.parent.gameObject.SetActive(true); SkyManager.water.GetComponent <PlanarReflectionSM>().enabled = true; /////////enable reflect //if (GUILayout.Button(new GUIContent("Add Underwater blur"), GUILayout.Width(150))) //{ if (Camera.main != null && Camera.main.gameObject.GetComponent <UnderWaterImageEffect>() == null) { Camera.main.gameObject.AddComponent <UnderWaterImageEffect>(); } else { Debug.Log("Add a main camera first"); } //LEFT-RIGHT VR CAMERAS //if (SkyManager.Mesh_Terrain_controller != null) //{ // if (TerrainManager.LeftCam != null && TerrainManager.LeftCam.GetComponent<UnderWaterImageEffect>() == null) // { // TerrainManager.LeftCam.AddComponent<UnderWaterImageEffect>(); // } // if (TerrainManager.RightCam != null && TerrainManager.RightCam.GetComponent<UnderWaterImageEffect>() == null) // { // TerrainManager.RightCam.AddComponent<UnderWaterImageEffect>(); // } //} //} } //check if volume script already on reflect camera if (SkyManager.water.GetComponent <PlanarReflectionSM>().m_ReflectionCameraOut != null && SkyManager.water.GetComponent <PlanarReflectionSM>().m_ReflectionCameraOut.GetComponent <FullVolumeCloudsSkyMaster>() != null) { //clouds exist already, handle this here FullVolumeCloudsSkyMaster Rclouds = SkyManager.water.GetComponent <PlanarReflectionSM>().m_ReflectionCameraOut.GetComponent <FullVolumeCloudsSkyMaster>(); CloudsScript.updateReflectionCamera = true; CloudsScript.reflectClouds = Rclouds; Debug.Log("Cloud script found on reflection camera, adding auto update based on main clouds system"); CloudsScript.reflectClouds.startDistance = 10000000000; //v4.8.5 CloudsScript.reflectClouds.Sun = CloudsScript.Sun; //v4.8.5 Rclouds.backgroundCam = CloudsScript.backgroundCam; //v5.0.5 } else { if (SkyManager.water.GetComponent <PlanarReflectionSM>().m_ReflectionCameraOut != null) //v4.8.5 { CloudsScript.updateReflectionCamera = true; CloudsScript.updateReflections(); //script.CloudsScript.updateReflectionCamera CloudsScript.reflectClouds._HorizonYAdjust = -500; CloudsScript.reflectClouds._FarDist = CloudsScript._FarDist / 2; //v4.8 CloudsScript.reflectClouds.isForReflections = true; //remove back layer from refections //int layerToCheck = LayerMask.NameToLayer("Background"); //backgroundCam.cullingMask = 1 << layerToCheck; SkyManager.water.GetComponent <PlanarReflectionSM>().m_ReflectionCameraOut.cullingMask &= ~(1 << layerToCheck); SkyManager.water.GetComponent <PlanarReflectionSM>().reflectionMask &= ~(1 << layerToCheck); //Debug.Log("Created clouds"); CloudsScript.reflectClouds.startDistance = 10000000000; //v4.8.5 CloudsScript.reflectClouds.Sun = CloudsScript.Sun; //v4.8.5 CloudsScript.reflectClouds.backgroundCam = CloudsScript.backgroundCam; //v5.0.5 } else { Debug.Log("No reflection camera in scene, please enable the water and Planer reflection script components."); } } } else { Debug.Log("Reflection cloud script already setup on reflect camera"); //v4.8 CloudsScript.updateReflectionCamera = true; CloudsScript.updateReflections(); CloudsScript.reflectClouds.isForReflections = true; //remove back layer from refections //backgroundCam.cullingMask = 1 << layerToCheck; SkyManager.water.GetComponent <PlanarReflectionSM>().m_ReflectionCameraOut.cullingMask &= ~(1 << layerToCheck); SkyManager.water.GetComponent <PlanarReflectionSM>().reflectionMask &= ~(1 << layerToCheck); CloudsScript.reflectClouds.startDistance = 10000000000; //v4.8.5 CloudsScript.reflectClouds.Sun = CloudsScript.Sun; //v4.8.5 CloudsScript.reflectClouds.backgroundCam = CloudsScript.backgroundCam; //v5.0.5 } } else { Debug.Log("No Water in scene, please add water component first in Water section"); } //ADD SHADOWS //FullVolumeCloudsSkyMaster CloudsScript = script.SkyManager.volumeClouds; if (CloudsScript != null && CloudsScript.shadowDome == null) { CloudsScript.setupShadows = true; CloudsScript.createShadowDome(); CloudsScript.shadowsUpdate(); } else { Debug.Log("Shadows already setup"); } //SET BACKLAYER //FullVolumeCloudsSkyMaster CloudsScript = script.SkyManager.volumeClouds; //v4.8.5 //var layerToCheck = LayerMask.NameToLayer("Background"); if (layerToCheck > -1) { if (CloudsScript != null && CloudsScript.backgroundCam == null) { CloudsScript.setupDepth = true; CloudsScript.createDepthSetup(); CloudsScript.setupDepth = true; CloudsScript.blendBackground = true; CloudsScript.reflectClouds.backgroundCam = CloudsScript.backgroundCam;//v5.0.5 } else { Debug.Log("Depth camera already setup"); } } else { Debug.Log("Please add the Background layer to proceed with the setup"); } //LIGHTNING //FullVolumeCloudsSkyMaster CloudsScript = SkyManager.volumeClouds; if (CloudsScript != null && CloudsScript.LightningBox == null) { CloudsScript.setupLightning = true; CloudsScript.createLightningBox(); //script.CloudsScript.shadowsUpdate (); CloudsScript.EnableLightning = true; CloudsScript.lightning_every = 5; CloudsScript.max_lightning_time = 9; } else { Debug.Log("Lightning components already setup"); } } else { Debug.Log("No Clouds"); } //VOLUME FOG SeasonalTerrainSKYMASTER TerrainManager = SkyManager.gameObject.GetComponent <SeasonalTerrainSKYMASTER>(); //if (GUILayout.Button(new GUIContent("Add volumetric fog"), GUILayout.Width(150))) //{ if (Camera.main != null && Camera.main.gameObject.GetComponent <GlobalFogSkyMaster>() == null) { Camera.main.gameObject.AddComponent <GlobalFogSkyMaster>(); Camera.main.gameObject.GetComponent <GlobalFogSkyMaster>().SkyManager = SkyManager; Camera.main.gameObject.GetComponent <GlobalFogSkyMaster>().Sun = SkyManager.SUN_LIGHT.transform; //Debug.Log("CAMERA FOUND"); TerrainManager.Lerp_gradient = true; TerrainManager.ImageEffectFog = true; TerrainManager.FogHeightByTerrain = true; } else { if (Camera.main == null) { Debug.Log("Add a main camera first"); } if (Camera.main.gameObject.GetComponent <GlobalFogSkyMaster>() != null) { //setup existing Camera.main.gameObject.GetComponent <GlobalFogSkyMaster>().SkyManager = SkyManager; Camera.main.gameObject.GetComponent <GlobalFogSkyMaster>().Sun = SkyManager.SUN_LIGHT.transform; TerrainManager.Lerp_gradient = true; TerrainManager.ImageEffectFog = true; TerrainManager.FogHeightByTerrain = true; } } //v4.8 TerrainManager.setVFogCurvesPresetE(); //} //END FOG //SHAFTS if (Camera.main != null && Camera.main.gameObject.GetComponent <SunShaftsSkyMaster>() == null) { Camera.main.gameObject.AddComponent <SunShaftsSkyMaster>(); Camera.main.gameObject.GetComponent <SunShaftsSkyMaster>().sunTransform = SkyManager.SunObj.transform; //Debug.Log("CAMERA FOUND"); TerrainManager.ImageEffectShafts = true; } else { if (Camera.main == null) { Debug.Log("Add a main camera first"); } if (Camera.main.gameObject.GetComponent <SunShaftsSkyMaster>() != null) { Camera.main.gameObject.GetComponent <SunShaftsSkyMaster>().sunTransform = SkyManager.SunObj.transform; TerrainManager.ImageEffectShafts = true; } } //END SHAFTS } else //find if camera in scene { } configured = true; this.enabled = false; } }
// Update is called once per frame void Update () { if (Time.fixedTime - change_time > changeWeatherInterval) { //do change based on randomizer weatherChoice = Random.Range(0,7);//for integers min is included, max exluded (0 up to 6) change_time = Time.fixedTime; } //NOTE removed +0.1 modifier in shader volume clouds script (v3.4.8) for slower changes in cloud coloration transitions float Speed1 = 0.1f; if (affectWater && waterManager != null) { if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm) { waterManager.waterScaleOffset.y = Mathf.Lerp (waterManager.waterScaleOffset.y, 3.5f, Speed1 * Time.deltaTime); } else { waterManager.waterScaleOffset.y = Mathf.Lerp (waterManager.waterScaleOffset.y, 0, Speed1 * Time.deltaTime); } if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.SnowStorm) { waterManager.FresnelBias = Mathf.Lerp (waterManager.FresnelBias, -67, Speed1 * Time.deltaTime); if (waterManager.FresnelBias < -64) { waterManager.ReflectColor = Color.Lerp (waterManager.ReflectColor, new Color (155f / 255f, 220f / 255f, 220f / 255f), Speed1 * Time.deltaTime); waterManager.UseSkyGradient = false; } waterManager.ShoreBlendOffset = Mathf.Lerp (waterManager.ShoreBlendOffset, 0.1f, Speed1 * Time.deltaTime); } else { waterManager.FresnelBias = Mathf.Lerp (waterManager.FresnelBias, prevFresnelBias, Speed1 * Time.deltaTime); waterManager.UseSkyGradient = true; waterManager.ShoreBlendOffset = Mathf.Lerp (waterManager.ShoreBlendOffset, prevShoreBlendOffset, Speed1 * Time.deltaTime); } } if (affectFog) { SeasonalTerrainSKYMASTER terrainControl = skyManager.Terrain_controller; if (terrainControl == null) { terrainControl = skyManager.Mesh_Terrain_controller; } if (terrainControl != null) { terrainControl.UseFogCurves = true; terrainControl.SkyFogOn = true; terrainControl.HeightFogOn = true; if(affectFogParams){ terrainControl.fogGradientDistance = 0; //v3.4.9 terrainControl.VFogDistance = 12; } if (weatherChoice == 0) { terrainControl.fogDensity = Mathf.Lerp(terrainControl.fogDensity,0.1f,Speed1*Time.deltaTime); //for light rain, light snow terrainControl.AddFogHeightOffset = Mathf.Lerp(terrainControl.AddFogHeightOffset,700,Speed1*Time.deltaTime); } if (weatherChoice == 1 || weatherChoice == 5) { terrainControl.fogDensity = Mathf.Lerp(terrainControl.fogDensity,0.5f,Speed1*Time.deltaTime); //for rain, snow terrainControl.AddFogHeightOffset = Mathf.Lerp(terrainControl.AddFogHeightOffset,700,Speed1*Time.deltaTime); } if (weatherChoice == 2 || weatherChoice == 3 || weatherChoice == 4 || weatherChoice == 6) { terrainControl.fogDensity = Mathf.Lerp(terrainControl.fogDensity,2,Speed1*Time.deltaTime); //for heavy weather terrainControl.AddFogHeightOffset = Mathf.Lerp(terrainControl.AddFogHeightOffset,700,Speed1*Time.deltaTime); } } } float speed = 0.05f * cloudDensityChangeSpeed * Time.deltaTime; if (weatherChoice == 0) { skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.Cloudy; if(skyManager.VolShaderCloudsH != null){ skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.85f,speed); // -0.55f; } skyManager.WeatherSeverity = 0; currentWeather = "Sunny"; } if (weatherChoice == 1) { skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.Rain; if(skyManager.VolShaderCloudsH != null){ skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.25f,speed*2); // -0.25f; } skyManager.WeatherSeverity = 4; currentWeather = "Rain"; } if (weatherChoice == 2) { skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.Rain; if(skyManager.VolShaderCloudsH != null){ skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.20f,speed*4.5f); //-0.20f; } skyManager.WeatherSeverity = 10; currentWeather = "Heavy Rain"; } if (weatherChoice == 3) { skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.HeavyStorm; if(skyManager.VolShaderCloudsH != null){ skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.15f,speed*5); // -0.15f; skyManager.VolShaderCloudsH.StormCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.17f,speed*5); // -0.17f; } skyManager.WeatherSeverity = 4; currentWeather = "Storm"; } if (weatherChoice == 4) { skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.HeavyStorm; if(skyManager.VolShaderCloudsH != null){ skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.10f,speed*5); // -0.10f; skyManager.VolShaderCloudsH.StormCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.10f,speed*5); // -0.10f; } skyManager.WeatherSeverity = 10; currentWeather = "Heavy Storm"; } if (weatherChoice == 5) { skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.SnowStorm; if(skyManager.VolShaderCloudsH != null){ skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.25f,speed*2); // -0.10f; skyManager.VolShaderCloudsH.StormCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.25f,speed*2); // -0.10f; } skyManager.WeatherSeverity = 2; currentWeather = "Snow Storm"; } if (weatherChoice == 6) { skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.SnowStorm; if(skyManager.VolShaderCloudsH != null){ skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.15f,speed); // -0.10f; skyManager.VolShaderCloudsH.StormCoverage = Mathf.Lerp (skyManager.VolShaderCloudsH.ClearDayCoverage,-0.15f,speed); // -0.10f; } skyManager.WeatherSeverity = 10; currentWeather = "Heavy Snow Storm"; } }
// Update is called once per frame public void Update() { //if (OverridePeformance | RenewClouds) { //v4.8 - search for manager SeasonalTerrainSKYMASTER terrmanag = GetComponent <SeasonalTerrainSKYMASTER>(); if (TerrainManager == null && terrmanag != null) { TerrainManager = terrmanag; } if (UnityTerrainSnowMat != null && MeshTerrainSnowMat != null) { TerrainManager.TerrainMat = UnityTerrainSnowMat; SkyManager.SnowMat = MeshTerrainSnowMat; SkyManager.SnowMatTerrain = UnityTerrainSnowMat; } //v4.8 - add terrain manager directly, not during terrain setup and plug it in skymaster object if (TerrainManager == null && SkyManager != null) { //script.SkyManager.Unity_terrain.gameObject.AddComponent<SeasonalTerrainSKYMASTER>(); //script.TerrainManager = script.SkyManager.Unity_terrain.gameObject.GetComponent<SeasonalTerrainSKYMASTER>(); //script.TerrainManager.TerrainMat = UnityTerrainSnowMat; SkyManager.gameObject.AddComponent <SeasonalTerrainSKYMASTER>(); TerrainManager = SkyManager.gameObject.GetComponent <SeasonalTerrainSKYMASTER>(); //TerrainManager.TerrainMat = UnityTerrainSnowMat; //UnityTerrainSnowMat = UnityTerrainSnowMat; //MeshTerrainSnowMat = MeshTerrainSnowMat; TerrainManager.Mesh_moon = true; TerrainManager.Glow_moon = true; TerrainManager.Enable_trasition = true; TerrainManager.Fog_Sky_Update = true; TerrainManager.Foggy_Terrain = true; TerrainManager.Use_both_fogs = true; //script.TerrainManager.ImageEffectFog = true; //script.TerrainManager.ImageEffectShafts = true; TerrainManager.SkyManager = SkyManager; } if (Application.isPlaying && SkyManager != null) { bool Clouds_exist = false; if (SkyManager.currentWeather != null && SkyManager.currentWeather.VolumeScript != null) { Clouds_exist = true; } if (OverridePeformance) { if (Clouds_exist) { SkyManager.currentWeather.VolumeScript.DecoupledWind = DecoupleWind; SkyManager.currentWeather.VolumeScript.max_divider = SpreadToFrames; SkyManager.currentWeather.VolumeScript.UpdateInterval = UpdateInteraval; } } if (RenewClouds) { if (Clouds_exist) { SkyManager.currentWeather.VolumeScript.DestroyOnfadeOut = true; SkyManager.currentWeather.VolumeScript.Restore_on_bound = true; SkyManager.currentWeather.VolumeScript.Disable_on_bound = true; SkyManager.currentWeather.VolumeScript.SmoothInRate = FadeInSpeed; SkyManager.currentWeather.VolumeScript.SmoothOutRate = FadeOutSpeed; SkyManager.currentWeather.VolumeScript.max_fade_speed = MaxFadeTime; SkyManager.currentWeather.VolumeScript.Bound = Boundary; } } else { if (Clouds_exist) { //disable renew SkyManager.currentWeather.VolumeScript.DestroyOnfadeOut = false; SkyManager.currentWeather.VolumeScript.Restore_on_bound = false; SkyManager.currentWeather.VolumeScript.Disable_on_bound = false; // //reload previous values // SkyManager.currentWeather.VolumeScript.SmoothInRate = lastFadeInSpeed; // SkyManager.currentWeather.VolumeScript.SmoothOutRate = lastFadeOutSpeed; // SkyManager.currentWeather.VolumeScript.max_fade_speed = lastMaxFadeTime; // SkyManager.currentWeather.VolumeScript.Bound = lastBoundary; // // //save parameters for restore // lastFadeInSpeed = SkyManager.currentWeather.VolumeScript.SmoothInRate; // lastFadeOutSpeed = SkyManager.currentWeather.VolumeScript.SmoothOutRate; // lastMaxFadeTime = SkyManager.currentWeather.VolumeScript.max_fade_speed; // lastBoundary = SkyManager.currentWeather.VolumeScript.Bound; } } //} } }