fix:代码提初始化
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78f2203e361751f46b31dedca1ff5c37
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
public class EnviroConfiguration : ScriptableObject
|
||||
{
|
||||
public string version = "";
|
||||
public EnviroTimeModule timeModule;
|
||||
public EnviroLightingModule lightingModule;
|
||||
public EnviroReflectionsModule reflectionsModule;
|
||||
public EnviroSkyModule Sky;
|
||||
public EnviroFogModule fogModule;
|
||||
public EnviroVolumetricCloudsModule volumetricCloudModule;
|
||||
public EnviroFlatCloudsModule flatCloudModule;
|
||||
public EnviroWeatherModule Weather;
|
||||
public EnviroAuroraModule Aurora;
|
||||
public EnviroAudioModule Audio;
|
||||
public EnviroEffectsModule Effects;
|
||||
public EnviroLightningModule Lightning;
|
||||
public EnviroQualityModule Quality;
|
||||
public EnviroEnvironmentModule Environment;
|
||||
}
|
||||
|
||||
public class EnviroConfigurationCreation
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("Assets/Create/Enviro3/Configuration")]
|
||||
#endif
|
||||
public static EnviroConfiguration CreateMyAsset()
|
||||
{
|
||||
EnviroConfiguration config = ScriptableObject.CreateInstance<EnviroConfiguration>();
|
||||
config.version = "3.3.0";
|
||||
#if UNITY_EDITOR
|
||||
// Create and save the new profile with unique name
|
||||
string path = UnityEditor.AssetDatabase.GetAssetPath (UnityEditor.Selection.activeObject);
|
||||
if (path == "")
|
||||
{
|
||||
path = "Assets/Enviro 3 - Sky and Weather";
|
||||
}
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath (path + "/New " + "Enviro Configuration" + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset (config, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets ();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc64ab65e50ce2c4599abae516516185
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/EnviroConfiguration.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,99 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Enviro 3/Effect Removal Zone")]
|
||||
public class EnviroEffectRemovalZone : MonoBehaviour
|
||||
{
|
||||
public enum Mode
|
||||
{
|
||||
Spherical,
|
||||
Cubical
|
||||
}
|
||||
public Mode type;
|
||||
|
||||
[Range(-10f, 0f)]
|
||||
public float density = -10.0f;
|
||||
|
||||
public float radius = 1.0f;
|
||||
public float stretch = 2.0f;
|
||||
[Range(0, 1)]
|
||||
public float feather = 0.7f;
|
||||
|
||||
public Vector3 size = Vector3.one * 10;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if(EnviroManager.instance != null)
|
||||
AddToZoneToManager();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if(EnviroManager.instance != null)
|
||||
RemoveZoneFromManager();
|
||||
}
|
||||
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if(EnviroManager.instance != null)
|
||||
RemoveZoneFromManager();
|
||||
}
|
||||
|
||||
|
||||
void AddToZoneToManager()
|
||||
{
|
||||
bool addedToMgr = false;
|
||||
|
||||
for(int i = 0; i < EnviroManager.instance.removalZones.Count; i++)
|
||||
{
|
||||
if(EnviroManager.instance.removalZones[i] == this)
|
||||
{
|
||||
addedToMgr = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!addedToMgr)
|
||||
EnviroManager.instance.AddRemovalZone(this);
|
||||
}
|
||||
|
||||
void RemoveZoneFromManager()
|
||||
{
|
||||
for(int i = 0; i < EnviroManager.instance.removalZones.Count; i++)
|
||||
{
|
||||
if(EnviroManager.instance.removalZones[i] == this)
|
||||
EnviroManager.instance.RemoveRemovaleZone(EnviroManager.instance.removalZones[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
transform.localScale = size;
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
if(type == Mode.Spherical)
|
||||
{
|
||||
Matrix4x4 m = Matrix4x4.identity;
|
||||
Transform t = transform;
|
||||
m.SetTRS(t.position, t.rotation, new Vector3(1.0f, stretch, 1.0f));
|
||||
Gizmos.matrix = m;
|
||||
Gizmos.DrawWireSphere(Vector3.zero, radius);
|
||||
}
|
||||
else
|
||||
{
|
||||
Matrix4x4 m = Matrix4x4.identity;
|
||||
Transform t = transform;
|
||||
m.SetTRS(t.position, t.rotation, new Vector3(1.0f, 1.0f, 1.0f));
|
||||
Gizmos.matrix = m;
|
||||
Gizmos.DrawWireCube(Vector3.zero,t.localScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f148e630058c13941ba69625130d8d6d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/EnviroEffectRemovalZone.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,318 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
public static class EnviroHelper
|
||||
{
|
||||
public static string assetPath = "Assets/Enviro 3 - Sky and Weather";
|
||||
public static Vector3 PingPong (Vector3 value)
|
||||
{
|
||||
Vector3 result = value;
|
||||
|
||||
if (result.x > 1f)
|
||||
result.x = -1f;
|
||||
else if (result.x < -1f)
|
||||
result.x = 1f;
|
||||
|
||||
if (result.y > 1f)
|
||||
result.y = -1f;
|
||||
else if (result.y < -1f)
|
||||
result.y = 1f;
|
||||
|
||||
if (result.z > 1f)
|
||||
result.z = -1f;
|
||||
else if (result.z < -1f)
|
||||
result.z = 1f;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector2 PingPong (Vector2 value)
|
||||
{
|
||||
Vector2 result = value;
|
||||
|
||||
if (result.x > 1f)
|
||||
result.x = -1f;
|
||||
else if (result.x < -1f)
|
||||
result.x = 1f;
|
||||
|
||||
if (result.y > 1f)
|
||||
result.y = -1f;
|
||||
else if (result.y < -1f)
|
||||
result.y = 1f;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float Remap(float value, float from1, float to1, float from2, float to2)
|
||||
{
|
||||
return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
|
||||
}
|
||||
|
||||
public static void DestroyExtended (Object obj)
|
||||
{
|
||||
if(Application.isPlaying)
|
||||
{
|
||||
MonoBehaviour.Destroy(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
MonoBehaviour.DestroyImmediate(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Checks if Enviro Effects should render on this camera for URP/HDRP
|
||||
public static bool CanRenderOnCamera (Camera cam)
|
||||
{
|
||||
if(EnviroManager.instance != null)
|
||||
{
|
||||
//if (cam.hideFlags != HideFlags.None) return true;
|
||||
|
||||
if(cam.cameraType == CameraType.SceneView || cam.cameraType == CameraType.Reflection)
|
||||
return true;
|
||||
|
||||
if(cam == EnviroManager.instance.Camera)
|
||||
return true;
|
||||
|
||||
if(EnviroManager.instance.Objects.globalReflectionProbe != null && cam == EnviroManager.instance.Objects.globalReflectionProbe.renderCam)
|
||||
return true;
|
||||
|
||||
for (int i = 0; i < EnviroManager.instance.Cameras.Count; i++)
|
||||
{
|
||||
if(cam == EnviroManager.instance.Cameras[i].camera)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
///Get the Light component from Enviro Directional light if lighting module is activated or any other active directional light
|
||||
public static Light GetDirectionalLight ()
|
||||
{
|
||||
Light result = null;
|
||||
|
||||
if(EnviroManager.instance.Lighting != null)
|
||||
{
|
||||
if(EnviroManager.instance.Lighting.Settings.lightingMode == EnviroLighting.LightingMode.Single)
|
||||
{
|
||||
if(EnviroManager.instance.Objects.directionalLight != null)
|
||||
result = EnviroManager.instance.Objects.directionalLight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!EnviroManager.instance.isNight)
|
||||
{
|
||||
if(EnviroManager.instance.Objects.directionalLight != null)
|
||||
result = EnviroManager.instance.Objects.directionalLight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(EnviroManager.instance.Objects.additionalDirectionalLight != null)
|
||||
result = EnviroManager.instance.Objects.additionalDirectionalLight;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Find other Directional Lights in scene
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
Light[] results = GameObject.FindObjectsByType<Light>(FindObjectsSortMode.None);
|
||||
#else
|
||||
Light[] results = GameObject.FindObjectsOfType<Light>();
|
||||
#endif
|
||||
|
||||
|
||||
for(int i = 0; i < results.Length; i++)
|
||||
{
|
||||
if(results[i].type == LightType.Directional && results[i].gameObject.activeSelf && results[i].enabled)
|
||||
{
|
||||
result = results[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static void CreateBuffer(ref ComputeBuffer buffer, int count, int stride)
|
||||
{
|
||||
if (buffer != null && buffer.count == count)
|
||||
return;
|
||||
|
||||
if(buffer != null)
|
||||
{
|
||||
buffer.Release();
|
||||
buffer = null;
|
||||
}
|
||||
|
||||
if (count <= 0)
|
||||
return;
|
||||
|
||||
buffer = new ComputeBuffer(count, stride);
|
||||
}
|
||||
public static void ReleaseComputeBuffer(ref ComputeBuffer buffer)
|
||||
{
|
||||
if(buffer != null)
|
||||
buffer.Release();
|
||||
|
||||
buffer = null;
|
||||
}
|
||||
|
||||
|
||||
public static Vector4 GetProjectionExtents(Camera camera)
|
||||
{
|
||||
return GetProjectionExtents(camera, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
public static Vector4 GetProjectionExtents(Camera camera, float texelOffsetX, float texelOffsetY)
|
||||
{
|
||||
if (camera == null)
|
||||
return Vector4.zero;
|
||||
|
||||
float oneExtentY = camera.orthographic ? camera.orthographicSize : Mathf.Tan(0.5f * Mathf.Deg2Rad * camera.fieldOfView);
|
||||
float oneExtentX = oneExtentY * camera.aspect;
|
||||
float texelSizeX = oneExtentX / (0.5f * camera.pixelWidth);
|
||||
float texelSizeY = oneExtentY / (0.5f * camera.pixelHeight);
|
||||
float oneJitterX = texelSizeX * texelOffsetX;
|
||||
float oneJitterY = texelSizeY * texelOffsetY;
|
||||
|
||||
return new Vector4(oneExtentX, oneExtentY, oneJitterX, oneJitterY);
|
||||
}
|
||||
|
||||
public static Vector4 GetProjectionExtents(Camera camera, Camera.StereoscopicEye eye)
|
||||
{
|
||||
return GetProjectionExtents(camera, eye, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
public static Vector4 GetProjectionExtents(Camera camera, Camera.StereoscopicEye eye, float texelOffsetX, float texelOffsetY)
|
||||
{
|
||||
Matrix4x4 inv;
|
||||
|
||||
if(camera.stereoEnabled)
|
||||
inv = Matrix4x4.Inverse(camera.GetStereoProjectionMatrix(eye));
|
||||
else
|
||||
inv = Matrix4x4.Inverse(camera.projectionMatrix);
|
||||
|
||||
Vector3 ray00 = inv.MultiplyPoint3x4(new Vector3(-1.0f, -1.0f, 0.95f));
|
||||
Vector3 ray11 = inv.MultiplyPoint3x4(new Vector3(1.0f, 1.0f, 0.95f));
|
||||
|
||||
ray00 /= -ray00.z;
|
||||
ray11 /= -ray11.z;
|
||||
|
||||
float oneExtentX = 0.5f * (ray11.x - ray00.x);
|
||||
float oneExtentY = 0.5f * (ray11.y - ray00.y);
|
||||
float texelSizeX = oneExtentX / (0.5f * camera.pixelWidth);
|
||||
float texelSizeY = oneExtentY / (0.5f * camera.pixelHeight);
|
||||
float oneJitterX = 0.5f * (ray11.x + ray00.x) + texelSizeX * texelOffsetX;
|
||||
float oneJitterY = 0.5f * (ray11.y + ray00.y) + texelSizeY * texelOffsetY;
|
||||
|
||||
return new Vector4(oneExtentX, oneExtentY, oneJitterX, oneJitterY);
|
||||
}
|
||||
|
||||
public static EnviroQuality GetQualityForCamera(Camera cam)
|
||||
{
|
||||
if(EnviroManager.instance.Quality != null)
|
||||
{
|
||||
EnviroQuality myQuality = EnviroManager.instance.Quality.Settings.defaultQuality;
|
||||
|
||||
for(int i = 0; i < EnviroManager.instance.Cameras.Count; i++)
|
||||
{
|
||||
if(EnviroManager.instance.Cameras[i].camera != null && EnviroManager.instance.Cameras[i].camera == cam && EnviroManager.instance.Cameras[i].quality != null)
|
||||
{
|
||||
myQuality = EnviroManager.instance.Cameras[i].quality;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return myQuality;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static bool ResetMatrix(Camera cam)
|
||||
{
|
||||
for(int i = 0; i < EnviroManager.instance.Cameras.Count; i++)
|
||||
{
|
||||
if(EnviroManager.instance.Cameras[i].camera != null && EnviroManager.instance.Cameras[i].camera == cam)
|
||||
{
|
||||
return EnviroManager.instance.Cameras[i].resetMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Find the default profile.
|
||||
public static EnviroModule GetDefaultPreset(string name)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
string[] assets = UnityEditor.AssetDatabase.FindAssets(name, null);
|
||||
|
||||
for (int idx = 0; idx < assets.Length; idx++)
|
||||
{
|
||||
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(assets[idx]);
|
||||
|
||||
if (path.Contains(".asset"))
|
||||
{
|
||||
return UnityEditor.AssetDatabase.LoadAssetAtPath<EnviroModule>(path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
|
||||
//Find the default profile. .y
|
||||
public static EnviroConfiguration GetConfig(string name)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
string[] assets = UnityEditor.AssetDatabase.FindAssets(name, null);
|
||||
|
||||
for (int idx = 0; idx < assets.Length; idx++)
|
||||
{
|
||||
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(assets[idx]);
|
||||
|
||||
if (path.Contains(".asset"))
|
||||
{
|
||||
return UnityEditor.AssetDatabase.LoadAssetAtPath<EnviroConfiguration>(path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
|
||||
#if ENVIRO_HDRP
|
||||
public static UnityEngine.Rendering.VolumeProfile GetDefaultSkyAndFogProfile(string name)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
string[] assets = UnityEditor.AssetDatabase.FindAssets(name, null);
|
||||
|
||||
for (int idx = 0; idx < assets.Length; idx++)
|
||||
{
|
||||
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(assets[idx]);
|
||||
|
||||
if (path.Contains(name + ".asset"))
|
||||
{
|
||||
return UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.Rendering.VolumeProfile>(path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 992dbce712f18c64fb4e2f2f3a09d8c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.2.0
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/EnviroHelper.cs
|
||||
uploadId: 721859
|
||||
@@ -0,0 +1,662 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class EnviroManager : EnviroManagerBase
|
||||
{
|
||||
private static EnviroManager _instance; // Creat a static instance for easy access!
|
||||
|
||||
public static EnviroManager instance
|
||||
{
|
||||
get
|
||||
{
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
if (_instance == null)
|
||||
_instance = GameObject.FindAnyObjectByType<EnviroManager>();
|
||||
#else
|
||||
if (_instance == null)
|
||||
_instance = GameObject.FindObjectOfType<EnviroManager>();
|
||||
#endif
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
//General
|
||||
public GeneralObjects Objects = new GeneralObjects();
|
||||
|
||||
//Setup
|
||||
public bool dontDestroyOnLoad;
|
||||
public Camera Camera;
|
||||
public string CameraTag = "MainCamera";
|
||||
public List<EnviroCameras> Cameras = new List<EnviroCameras>();
|
||||
[Tooltip("'Optional': Assign a transform here to change what object Enviro and weather effects should follow. If not set it will use the camera transform.")]
|
||||
public Transform optionalFollowTransform;
|
||||
|
||||
//Inspector
|
||||
public bool showSetup;
|
||||
public bool showModules;
|
||||
public bool showEvents;
|
||||
public bool showThirdParty;
|
||||
|
||||
// Publics
|
||||
[Range(0.2f,0.7f)]
|
||||
public float dayNightSwitch = 0.45f;
|
||||
public bool isNight;
|
||||
public float solarTime;
|
||||
public float lunarTime;
|
||||
public bool notFirstFrame = false;
|
||||
|
||||
//Effect Removal Zones
|
||||
public List<EnviroEffectRemovalZone> removalZones = new List<EnviroEffectRemovalZone>();
|
||||
|
||||
struct ZoneParams
|
||||
{
|
||||
public float type;
|
||||
public Vector3 pos;
|
||||
public float radius;
|
||||
public Vector3 size;
|
||||
public Vector3 axis;
|
||||
public float stretch;
|
||||
public float density;
|
||||
public float feather;
|
||||
public Matrix4x4 transform;
|
||||
public float pad0;
|
||||
public float pad1;
|
||||
}
|
||||
|
||||
public ComputeBuffer clearZoneCB;
|
||||
public ComputeBuffer removeZoneParamsCB;
|
||||
public ComputeBuffer clearCBPoint;
|
||||
public ComputeBuffer clearCBSpot;
|
||||
|
||||
ZoneParams[] removalZoneParams;
|
||||
|
||||
//Non time module controls
|
||||
[Range(0f,360f)]
|
||||
public float sunRotationX;
|
||||
[Range(0f,360f)]
|
||||
public float sunRotationY;
|
||||
[Range(0f,360f)]
|
||||
public float moonRotationX;
|
||||
[Range(0f,360f)]
|
||||
public float moonRotationY;
|
||||
public bool showNonTimeControls;
|
||||
///////
|
||||
//Events
|
||||
public Enviro.EnviroEvents Events;
|
||||
public delegate void HourPassed();
|
||||
public delegate void DayPassed();
|
||||
public delegate void YearPassed();
|
||||
public delegate void WeatherChanged(EnviroWeatherType weatherType);
|
||||
public delegate void ZoneWeatherChanged(EnviroWeatherType weatherType, Enviro.EnviroZone zone);
|
||||
public delegate void SeasonChanged(EnviroEnvironment.Seasons season);
|
||||
public delegate void isNightEvent();
|
||||
public delegate void isDayEvent();
|
||||
|
||||
public event HourPassed OnHourPassed;
|
||||
public event DayPassed OnDayPassed;
|
||||
public event YearPassed OnYearPassed;
|
||||
public event WeatherChanged OnWeatherChanged;
|
||||
public event ZoneWeatherChanged OnZoneWeatherChanged;
|
||||
public event SeasonChanged OnSeasonChanged;
|
||||
public event isNightEvent OnNightTime;
|
||||
public event isDayEvent OnDayTime;
|
||||
|
||||
//Zones
|
||||
public EnviroZone currentZone;
|
||||
public EnviroZone defaultZone;
|
||||
public List<EnviroZone> zones = new List<EnviroZone>();
|
||||
|
||||
public virtual void NotifyHourPassed()
|
||||
{
|
||||
if (OnHourPassed != null)
|
||||
OnHourPassed();
|
||||
}
|
||||
public virtual void NotifyDayPassed()
|
||||
{
|
||||
if (OnDayPassed != null)
|
||||
OnDayPassed();
|
||||
}
|
||||
public virtual void NotifyYearPassed()
|
||||
{
|
||||
if (OnYearPassed != null)
|
||||
OnYearPassed();
|
||||
}
|
||||
public virtual void NotifyWeatherChanged(EnviroWeatherType type)
|
||||
{
|
||||
if (OnWeatherChanged != null)
|
||||
OnWeatherChanged(type);
|
||||
}
|
||||
public virtual void NotifyZoneWeatherChanged(EnviroWeatherType type, EnviroZone zone)
|
||||
{
|
||||
if (OnZoneWeatherChanged != null)
|
||||
OnZoneWeatherChanged(type, zone);
|
||||
}
|
||||
public virtual void NotifySeasonChanged(EnviroEnvironment.Seasons season)
|
||||
{
|
||||
if (OnSeasonChanged != null)
|
||||
OnSeasonChanged(season);
|
||||
}
|
||||
public virtual void NotifyIsNight()
|
||||
{
|
||||
if (OnNightTime != null)
|
||||
OnNightTime();
|
||||
}
|
||||
public virtual void NotifyIsDay()
|
||||
{
|
||||
if (OnDayTime != null)
|
||||
OnDayTime();
|
||||
}
|
||||
|
||||
//Event Invoke
|
||||
private void HourPassedInvoke()
|
||||
{
|
||||
Events.onHourPassedActions.Invoke();
|
||||
}
|
||||
private void DayPassedInvoke()
|
||||
{
|
||||
Events.onDayPassedActions.Invoke();
|
||||
}
|
||||
private void YearPassedInvoke()
|
||||
{
|
||||
Events.onYearPassedActions.Invoke();
|
||||
}
|
||||
private void WeatherChangedInvoke()
|
||||
{
|
||||
Events.onWeatherChangedActions.Invoke();
|
||||
}
|
||||
private void SeasonsChangedInvoke()
|
||||
{
|
||||
Events.onSeasonChangedActions.Invoke();
|
||||
}
|
||||
private void NightTimeInvoke()
|
||||
{
|
||||
Events.onNightActions.Invoke ();
|
||||
}
|
||||
private void DayTimeInvoke()
|
||||
{
|
||||
Events.onDayActions.Invoke ();
|
||||
}
|
||||
private void ZoneChangedInvoke()
|
||||
{
|
||||
Events.onZoneChangedActions.Invoke ();
|
||||
}
|
||||
|
||||
//Lighting updates
|
||||
public bool updateSkyAndLighting = true;
|
||||
public bool updateSkyAndLightingHDRP = true;
|
||||
|
||||
// HDRP
|
||||
#if ENVIRO_HDRP
|
||||
public UnityEngine.Rendering.Volume volumeHDRP;
|
||||
public UnityEngine.Rendering.VolumeProfile volumeProfileHDRP;
|
||||
public UnityEngine.Rendering.HighDefinition.CustomPassVolume customPassVolumeHDRP;
|
||||
#endif
|
||||
//////
|
||||
|
||||
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if(UnityEditor.PrefabUtility.IsPartOfAnyPrefab(gameObject))
|
||||
UnityEditor.PrefabUtility.UnpackPrefabInstance(gameObject,UnityEditor.PrefabUnpackMode.OutermostRoot,UnityEditor.InteractionMode.UserAction);
|
||||
#endif
|
||||
|
||||
if(configuration == null)
|
||||
Debug.Log("Please create or assign a configuration asset in your Enviro Manager!");
|
||||
|
||||
CreateGeneralObjects ();
|
||||
#if ENVIRO_HDRP
|
||||
CreateHDRPVolume ();
|
||||
#endif
|
||||
UpdateManager();
|
||||
EnableModules();
|
||||
|
||||
#if !ENVIRO_HDRP && !ENVIRO_URP
|
||||
//Add Enviro Render Component to main camera in builtin rp
|
||||
AddCameraComponents();
|
||||
#endif
|
||||
|
||||
EventInit();
|
||||
SetSRPKeywords ();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if(Fog != null)
|
||||
Fog.Disable();
|
||||
|
||||
ReleaseZoneBuffers();
|
||||
}
|
||||
|
||||
private void AddCameraComponents()
|
||||
{
|
||||
if(Camera != null)
|
||||
{
|
||||
if(Camera.gameObject.GetComponent<EnviroRenderer>() == null)
|
||||
Camera.gameObject.AddComponent<EnviroRenderer>();
|
||||
}
|
||||
|
||||
for(int i = 0; i < Cameras.Count; i++)
|
||||
{
|
||||
if(Cameras[i].camera != null)
|
||||
{
|
||||
if(Cameras[i].camera.gameObject.GetComponent<EnviroRenderer>() == null)
|
||||
Cameras[i].camera.gameObject.AddComponent<EnviroRenderer>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change the camera to a new one.
|
||||
public void ChangeCamera (Camera cam)
|
||||
{
|
||||
Camera = cam;
|
||||
|
||||
#if !ENVIRO_HDRP && !ENVIRO_URP
|
||||
AddCameraComponents();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void AddAdditionalCamera (Camera cam, bool reset = false)
|
||||
{
|
||||
bool added = false;
|
||||
|
||||
for(int i = 0; i < Cameras.Count; i++)
|
||||
{
|
||||
if(Cameras[i].camera != null && Cameras[i].camera == cam)
|
||||
added = true;
|
||||
}
|
||||
|
||||
if(!added)
|
||||
{
|
||||
EnviroCameras newCam = new EnviroCameras();
|
||||
newCam.camera = cam;
|
||||
newCam.resetMatrix = reset;
|
||||
|
||||
Cameras.Add(newCam);
|
||||
#if !ENVIRO_HDRP && !ENVIRO_URP
|
||||
AddCameraComponents();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
|
||||
// Set dont destroy on load on start
|
||||
if(dontDestroyOnLoad && Application.isPlaying)
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
//Set a first frame bool that will be used for events.
|
||||
notFirstFrame = false;
|
||||
StartCoroutine(FirstFrame());
|
||||
|
||||
StartModules ();
|
||||
}
|
||||
|
||||
//Update modules
|
||||
void Update()
|
||||
{
|
||||
if(!Application.isPlaying)
|
||||
LoadConfiguration();
|
||||
|
||||
UpdateManager ();
|
||||
|
||||
//Update all modules
|
||||
UpdateModules ();
|
||||
|
||||
//Update non time case
|
||||
if(Time == null)
|
||||
UpdateNonTime();
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if(Camera != null)
|
||||
{
|
||||
if(optionalFollowTransform != null)
|
||||
{
|
||||
transform.position = optionalFollowTransform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.position = Camera.transform.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CreateGeneralObjects ()
|
||||
{
|
||||
if(Objects.sun == null)
|
||||
{
|
||||
Objects.sun = new GameObject();
|
||||
Objects.sun.name = "Sun";
|
||||
Objects.sun.transform.SetParent(transform);
|
||||
Objects.sun.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
if(Objects.moon == null)
|
||||
{
|
||||
Objects.moon = new GameObject();
|
||||
Objects.moon.name = "Moon";
|
||||
Objects.moon.transform.SetParent(transform);
|
||||
Objects.moon.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
if(Objects.stars == null)
|
||||
{
|
||||
Objects.stars = new GameObject();
|
||||
Objects.stars.name = "Stars";
|
||||
Objects.stars.transform.SetParent(transform);
|
||||
Objects.stars.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the solar and lunar time based on sun rotation.
|
||||
public void UpdateNonTime()
|
||||
{
|
||||
if(Objects.sun != null)
|
||||
{
|
||||
Objects.sun.transform.eulerAngles = new Vector3(sunRotationX,sunRotationY,0f);
|
||||
|
||||
if(sunRotationX > 0f && sunRotationX <= 90f)
|
||||
solarTime = EnviroHelper.Remap(sunRotationX, 0f, 90f, 0.5f, 1f);
|
||||
else if (sunRotationX > 90f && sunRotationX <= 180f)
|
||||
solarTime = EnviroHelper.Remap(sunRotationX, 90f, 180f, 1f, 0.5f);
|
||||
else if (sunRotationX > 180f && sunRotationX <= 270f)
|
||||
solarTime = EnviroHelper.Remap(sunRotationX, 180f, 270f, 0.5f, 0.0f);
|
||||
else if (sunRotationX > 270f && sunRotationX <= 360f)
|
||||
solarTime = EnviroHelper.Remap(sunRotationX, 270f, 360f, 0.0f, 0.5f);
|
||||
else solarTime = 0.5f;
|
||||
}
|
||||
if(Objects.moon != null)
|
||||
{
|
||||
Objects.moon.transform.eulerAngles = new Vector3(moonRotationX,moonRotationY,0f);
|
||||
|
||||
if(moonRotationX > 0f && moonRotationX <= 90f)
|
||||
lunarTime = EnviroHelper.Remap(moonRotationX, 0f, 90f, 0.5f, 1f);
|
||||
else if (moonRotationX > 90f && moonRotationX <= 180f)
|
||||
lunarTime = EnviroHelper.Remap(moonRotationX, 90f, 180f, 1f, 0.5f);
|
||||
else if (moonRotationX > 180f && moonRotationX <= 270f)
|
||||
lunarTime = EnviroHelper.Remap(moonRotationX, 180f, 270f, 0.5f, 0.0f);
|
||||
else if (moonRotationX > 270f && moonRotationX <= 360f)
|
||||
lunarTime = EnviroHelper.Remap(moonRotationX, 270f, 360f, 0.0f, 0.5f);
|
||||
else lunarTime = 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
//Effect Removal Zones
|
||||
public bool AddRemovalZone (EnviroEffectRemovalZone zone)
|
||||
{
|
||||
removalZones.Add(zone);
|
||||
return true;
|
||||
}
|
||||
public void RemoveRemovaleZone (EnviroEffectRemovalZone zone)
|
||||
{
|
||||
|
||||
if(removalZones.Contains(zone))
|
||||
removalZones.Remove(zone);
|
||||
|
||||
}
|
||||
|
||||
private void SetupZoneBuffers()
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (int z = 0; z < removalZones.Count; z++)
|
||||
{
|
||||
if (removalZones[z] != null && removalZones[z].enabled && removalZones[z].gameObject.activeSelf)
|
||||
count++;
|
||||
}
|
||||
|
||||
Shader.SetGlobalFloat("_EnviroRemovalZonesCount", count);
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
// Can't not set the buffer
|
||||
Shader.SetGlobalBuffer("_EnviroRemovalZones", clearZoneCB);
|
||||
return;
|
||||
}
|
||||
|
||||
if (removalZoneParams == null || removalZoneParams.Length != count)
|
||||
removalZoneParams = new ZoneParams[count];
|
||||
|
||||
int zoneID = 0;
|
||||
for (int i = 0; i < removalZones.Count; i++)
|
||||
{
|
||||
Enviro.EnviroEffectRemovalZone fz = removalZones[i];
|
||||
if (fz == null || !fz.enabled || !fz.gameObject.activeSelf)
|
||||
continue;
|
||||
|
||||
Transform t = fz.transform;
|
||||
|
||||
removalZoneParams[zoneID].type = (int)fz.type;
|
||||
removalZoneParams[zoneID].pos = t.position;
|
||||
removalZoneParams[zoneID].radius = fz.radius * fz.radius;
|
||||
removalZoneParams[zoneID].size = fz.size;
|
||||
removalZoneParams[zoneID].axis = -t.up;
|
||||
removalZoneParams[zoneID].stretch = 1.0f/fz.stretch - 1.0f;
|
||||
removalZoneParams[zoneID].density = fz.density;
|
||||
removalZoneParams[zoneID].feather = 1.0f - fz.feather;
|
||||
removalZoneParams[zoneID].transform = t.transform.worldToLocalMatrix;
|
||||
removalZoneParams[zoneID].pad0 = 0f;
|
||||
removalZoneParams[zoneID].pad1 = 0f;
|
||||
|
||||
zoneID++;
|
||||
}
|
||||
removeZoneParamsCB.SetData(removalZoneParams);
|
||||
Shader.SetGlobalBuffer("_EnviroRemovalZones", removeZoneParamsCB);
|
||||
}
|
||||
|
||||
private void CreateZoneBuffers()
|
||||
{
|
||||
EnviroHelper.CreateBuffer(ref removeZoneParamsCB, removalZones.Count, Marshal.SizeOf(typeof(ZoneParams)));
|
||||
EnviroHelper.CreateBuffer(ref clearZoneCB, 1, 4);
|
||||
}
|
||||
|
||||
private void ReleaseZoneBuffers()
|
||||
{
|
||||
if(removeZoneParamsCB != null)
|
||||
EnviroHelper.ReleaseComputeBuffer(ref removeZoneParamsCB);
|
||||
if(clearZoneCB != null)
|
||||
EnviroHelper.ReleaseComputeBuffer(ref clearZoneCB);
|
||||
}
|
||||
|
||||
IEnumerator FirstFrame ()
|
||||
{
|
||||
yield return 0;
|
||||
notFirstFrame = true;
|
||||
}
|
||||
|
||||
///HDRP Section
|
||||
public void CreateHDRPVolume ()
|
||||
{
|
||||
#if ENVIRO_HDRP
|
||||
if(volumeProfileHDRP == null)
|
||||
{
|
||||
volumeProfileHDRP = EnviroHelper.GetDefaultSkyAndFogProfile("Enviro HDRP Sky and Fog Volume");
|
||||
}
|
||||
|
||||
if(volumeHDRP == null)
|
||||
{
|
||||
GameObject volume = new GameObject();
|
||||
volume.name = "Enviro Sky and Fog Volume";
|
||||
volume.transform.SetParent(transform);
|
||||
volume.transform.localPosition = Vector3.zero;
|
||||
volumeHDRP = volume.AddComponent<UnityEngine.Rendering.Volume>();
|
||||
volumeHDRP.sharedProfile = volumeProfileHDRP;
|
||||
volumeHDRP.priority = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
volumeHDRP.sharedProfile = volumeProfileHDRP;
|
||||
}
|
||||
|
||||
if(customPassVolumeHDRP == null)
|
||||
{
|
||||
GameObject volume = new GameObject();
|
||||
volume.name = "Enviro Custom Pass";
|
||||
volume.transform.SetParent(transform);
|
||||
volume.transform.localPosition = Vector3.zero;
|
||||
customPassVolumeHDRP = volume.AddComponent<UnityEngine.Rendering.HighDefinition.CustomPassVolume>();
|
||||
customPassVolumeHDRP.isGlobal = true;
|
||||
customPassVolumeHDRP.injectionPoint = UnityEngine.Rendering.HighDefinition.CustomPassInjectionPoint.AfterOpaqueAndSky;
|
||||
customPassVolumeHDRP.AddPassOfType<EnviroHDRPCustomPass>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if a pass of type EnviroHDRPCustomPass already exists
|
||||
bool hasPass = false;
|
||||
foreach (var pass in customPassVolumeHDRP.customPasses)
|
||||
{
|
||||
if (pass is EnviroHDRPCustomPass)
|
||||
{
|
||||
hasPass = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!hasPass)
|
||||
customPassVolumeHDRP.AddPassOfType<EnviroHDRPCustomPass>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void CheckCameraSetup ()
|
||||
{
|
||||
//Auto assign camera with the camera tag when camera not set.
|
||||
if(Camera == null)
|
||||
{
|
||||
for (int i = 0; i < Camera.allCameras.Length; i++)
|
||||
{
|
||||
if (Camera.allCameras[i].tag == CameraTag)
|
||||
{
|
||||
Camera = Camera.allCameras[i];
|
||||
#if !ENVIRO_HDRP || !ENVIRO_URP
|
||||
AddCameraComponents();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetSRPKeywords ()
|
||||
{
|
||||
#if ENVIRO_HDRP
|
||||
Shader.EnableKeyword("ENVIROHDRP");
|
||||
Shader.DisableKeyword("ENVIROURP");
|
||||
#elif ENVIRO_URP
|
||||
Shader.EnableKeyword("ENVIROURP");
|
||||
Shader.DisableKeyword("ENVIROHDRP");
|
||||
#else
|
||||
Shader.DisableKeyword("ENVIROURP");
|
||||
Shader.DisableKeyword("ENVIROHDRP");
|
||||
#endif
|
||||
}
|
||||
|
||||
//Saves time and weather conditions
|
||||
public void Save()
|
||||
{
|
||||
if(Time != null)
|
||||
{
|
||||
PlayerPrefs.SetFloat("Time_Hours", Time.GetTimeOfDay());
|
||||
PlayerPrefs.SetInt("Time_Days", Time.days);
|
||||
PlayerPrefs.SetInt("Time_Months", Time.months);
|
||||
PlayerPrefs.SetInt("Time_Years", Time.years);
|
||||
}
|
||||
|
||||
if(Weather != null)
|
||||
{
|
||||
for (int i = 0; i < Weather.Settings.weatherTypes.Count; i++)
|
||||
{
|
||||
if (Weather.Settings.weatherTypes[i] == Weather.targetWeatherType)
|
||||
PlayerPrefs.SetInt("currentWeather", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Loads time and weather conditions
|
||||
public void Load()
|
||||
{
|
||||
if(Time != null)
|
||||
{
|
||||
if (PlayerPrefs.HasKey("Time_Hours"))
|
||||
Time.SetTimeOfDay(PlayerPrefs.GetFloat("Time_Hours"));
|
||||
if (PlayerPrefs.HasKey("Time_Days"))
|
||||
Time.days = PlayerPrefs.GetInt("Time_Days");
|
||||
if (PlayerPrefs.HasKey("Time_Months"))
|
||||
Time.months = PlayerPrefs.GetInt("Time_Months");
|
||||
if (PlayerPrefs.HasKey("Time_Years"))
|
||||
Time.years = PlayerPrefs.GetInt("Time_Years");
|
||||
}
|
||||
if(Weather != null)
|
||||
{
|
||||
if (PlayerPrefs.HasKey("currentWeather"))
|
||||
Weather.ChangeWeatherInstant(PlayerPrefs.GetInt("currentWeather"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Events
|
||||
private void EventInit()
|
||||
{
|
||||
if(Time != null)
|
||||
{
|
||||
OnHourPassed += () => HourPassedInvoke ();
|
||||
OnDayPassed += () => DayPassedInvoke ();
|
||||
OnYearPassed += () => YearPassedInvoke ();
|
||||
|
||||
OnNightTime += () => NightTimeInvoke ();
|
||||
OnDayTime += () => DayTimeInvoke ();
|
||||
}
|
||||
|
||||
if(Weather != null)
|
||||
{
|
||||
OnWeatherChanged += (EnviroWeatherType type) => WeatherChangedInvoke ();
|
||||
OnZoneWeatherChanged += (EnviroWeatherType type, EnviroZone zone) => ZoneChangedInvoke ();
|
||||
}
|
||||
|
||||
if(Environment != null)
|
||||
{
|
||||
OnSeasonChanged += (EnviroEnvironment.Seasons season) => SeasonsChangedInvoke ();
|
||||
}
|
||||
}
|
||||
|
||||
//Updates manager variables.
|
||||
private void UpdateManager ()
|
||||
{
|
||||
if(Application.isPlaying)
|
||||
CheckCameraSetup ();
|
||||
|
||||
if(solarTime > dayNightSwitch)
|
||||
{
|
||||
if(isNight == true)
|
||||
NotifyIsDay();
|
||||
|
||||
isNight = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isNight == false)
|
||||
NotifyIsNight();
|
||||
|
||||
isNight = true;
|
||||
}
|
||||
|
||||
//Effect Removal Zones:
|
||||
if(Fog != null || Effects != null)
|
||||
{
|
||||
CreateZoneBuffers();
|
||||
SetupZoneBuffers();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43b4e18e1baccc642a82a5e642fd6997
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.2.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/EnviroManager.cs
|
||||
uploadId: 766468
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fffe30901d9a0504984f7fcdb6475eff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/EnviroManagerBase.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 931b9d5510e793d4bbea908c1229f55b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,285 @@
|
||||
#if ENVIRO_HDRP
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
class EnviroHDRPCustomPass : CustomPass
|
||||
{
|
||||
private Material blitTrough;
|
||||
private List<EnviroVolumetricCloudRenderer> volumetricCloudsRender = new List<EnviroVolumetricCloudRenderer>();
|
||||
private Vector3 floatingPointOriginMod = Vector3.zero;
|
||||
|
||||
private RTHandle sourceHandle;
|
||||
private RTHandle temp1Handle;
|
||||
private RTHandle temp2Handle;
|
||||
|
||||
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
|
||||
{
|
||||
if (blitTrough == null)
|
||||
blitTrough = new Material(Shader.Find("Hidden/Enviro/BlitTroughHDRP"));
|
||||
|
||||
// We allocate persistent RTHandles dynamically when Execute runs for the first time
|
||||
sourceHandle = null;
|
||||
temp1Handle = null;
|
||||
temp2Handle = null;
|
||||
}
|
||||
|
||||
|
||||
public RTHandle ReallocateIfNeeded(RTHandle handle, RenderTextureDescriptor desc, string name)
|
||||
{
|
||||
bool needsRealloc = handle == null || handle.rt == null;
|
||||
|
||||
if (!needsRealloc)
|
||||
{
|
||||
var hDesc = handle.rt.descriptor;
|
||||
|
||||
// Compare only the format & dimension
|
||||
if (hDesc.graphicsFormat != desc.graphicsFormat ||
|
||||
hDesc.dimension != desc.dimension)
|
||||
{
|
||||
needsRealloc = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needsRealloc)
|
||||
{
|
||||
if (handle != null)
|
||||
RTHandles.Release(handle);
|
||||
|
||||
// Allocate with scale = 1, dynamic scaling will adjust automatically
|
||||
handle = RTHandles.Alloc(
|
||||
Vector2.one,
|
||||
colorFormat: desc.graphicsFormat,
|
||||
dimension: desc.dimension,
|
||||
enableRandomWrite: false,
|
||||
useMipMap: desc.useMipMap,
|
||||
name: name,
|
||||
useDynamicScale: true
|
||||
);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
protected override void Execute(CustomPassContext ctx)
|
||||
{
|
||||
HDCamera camera = ctx.hdCamera;
|
||||
|
||||
if (ctx.cameraColorBuffer == null || ctx.cameraColorBuffer.rt == null ||
|
||||
camera.camera.cameraType == CameraType.Preview ||
|
||||
!EnviroHelper.CanRenderOnCamera(camera.camera) || EnviroManager.instance == null && EnviroManager.instance.configuration != null)
|
||||
return;
|
||||
|
||||
|
||||
var desc = ctx.cameraColorBuffer.rt.descriptor;
|
||||
|
||||
// Reallocate only if needed
|
||||
sourceHandle = ReallocateIfNeeded(sourceHandle, desc, "Enviro Source");
|
||||
temp1Handle = ReallocateIfNeeded(temp1Handle, desc, "Enviro Temp1");
|
||||
|
||||
if (EnviroManager.instance.VolumetricClouds != null && EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows)
|
||||
temp2Handle = ReallocateIfNeeded(temp2Handle, desc, "Enviro Temp2");
|
||||
|
||||
|
||||
|
||||
// Copy camera buffer to persistent source
|
||||
HDUtils.BlitCameraTexture(ctx.cmd, ctx.cameraColorBuffer, sourceHandle);
|
||||
|
||||
// Get quality and flags
|
||||
EnviroQuality myQuality = EnviroHelper.GetQualityForCamera(camera.camera);
|
||||
bool renderVolumetricClouds = EnviroManager.instance.VolumetricClouds != null && myQuality.volumetricCloudsOverride.volumetricClouds;
|
||||
bool renderFog = EnviroManager.instance.Fog != null && myQuality.fogOverride.fog;
|
||||
|
||||
floatingPointOriginMod = EnviroManager.instance.Objects?.worldAnchor != null
|
||||
? EnviroManager.instance.Objects.worldAnchor.transform.position
|
||||
: Vector3.zero;
|
||||
|
||||
// Ensure clouds renderer exists
|
||||
if (renderVolumetricClouds && GetCloudsRenderer(camera.camera) == null)
|
||||
CreateCloudsRenderer(camera.camera);
|
||||
|
||||
SetMatrix(camera.camera);
|
||||
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(camera.camera);
|
||||
|
||||
// ----- Depth-aware render logic -----
|
||||
if (renderVolumetricClouds && renderFog)
|
||||
{
|
||||
if (camera.camera.transform.position.y - floatingPointOriginMod.y < EnviroManager.instance.VolumetricClouds.settingsVolume.bottomCloudsHeight)
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera, ctx.cmd, sourceHandle, temp1Handle, renderer, myQuality);
|
||||
|
||||
if (EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows &&
|
||||
camera.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsHDRP(camera.camera, ctx.cmd, temp1Handle, temp2Handle, renderer);
|
||||
|
||||
EnviroManager.instance.Fog.RenderHeightFogHDRP(camera.camera, ctx.cmd, temp2Handle, ctx.cameraColorBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
EnviroManager.instance.Fog.RenderHeightFogHDRP(camera.camera, ctx.cmd, temp1Handle, ctx.cameraColorBuffer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
EnviroManager.instance.Fog.RenderHeightFogHDRP(camera.camera, ctx.cmd, sourceHandle, temp1Handle);
|
||||
|
||||
if (EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows &&
|
||||
camera.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsHDRP(camera.camera, ctx.cmd, temp1Handle, temp2Handle, renderer);
|
||||
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera, ctx.cmd, temp2Handle, ctx.cameraColorBuffer, renderer, myQuality);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera, ctx.cmd, temp1Handle, ctx.cameraColorBuffer, renderer, myQuality);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (renderVolumetricClouds)
|
||||
{
|
||||
if (EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows &&
|
||||
camera.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsHDRP(camera.camera, ctx.cmd, sourceHandle, temp1Handle, renderer);
|
||||
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera, ctx.cmd, temp1Handle, ctx.cameraColorBuffer, renderer, myQuality);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera, ctx.cmd, sourceHandle, ctx.cameraColorBuffer, renderer, myQuality);
|
||||
}
|
||||
}
|
||||
else if (renderFog)
|
||||
{
|
||||
|
||||
EnviroManager.instance.Fog.RenderHeightFogHDRP(camera.camera, ctx.cmd, sourceHandle, ctx.cameraColorBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// blitTrough.SetTexture("_InputTexture", sourceHandle);
|
||||
// CoreUtils.SetRenderTarget(ctx.cmd, ctx.cameraColorBuffer, ctx.cameraDepthBuffer, ClearFlag.None);
|
||||
// HDUtils.DrawFullScreen(ctx.cmd, blitTrough);
|
||||
}
|
||||
|
||||
if (!renderVolumetricClouds)
|
||||
Shader.SetGlobalTexture("_EnviroClouds", Texture2D.blackTexture);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void Cleanup()
|
||||
{
|
||||
if (blitTrough != null) CoreUtils.Destroy(blitTrough);
|
||||
|
||||
if (sourceHandle != null) RTHandles.Release(sourceHandle);
|
||||
if (temp1Handle != null) RTHandles.Release(temp1Handle);
|
||||
if (temp2Handle != null) RTHandles.Release(temp2Handle);
|
||||
|
||||
for (int i = 0; i < volumetricCloudsRender.Count; i++)
|
||||
CleanCloudsRenderer(volumetricCloudsRender[i]);
|
||||
}
|
||||
|
||||
// ---- Cloud renderer helpers -----
|
||||
private EnviroVolumetricCloudRenderer CreateCloudsRenderer(Camera cam)
|
||||
{
|
||||
EnviroVolumetricCloudRenderer r = new EnviroVolumetricCloudRenderer();
|
||||
r.camera = cam;
|
||||
volumetricCloudsRender.Add(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
private void CleanCloudsRenderer(EnviroVolumetricCloudRenderer renderer)
|
||||
{
|
||||
if (renderer.fullBuffer != null)
|
||||
foreach (var b in renderer.fullBuffer) if (b != null) CoreUtils.Destroy(b);
|
||||
|
||||
if (renderer.undersampleBuffer != null) CoreUtils.Destroy(renderer.undersampleBuffer);
|
||||
if (renderer.downsampledDepth != null) CoreUtils.Destroy(renderer.downsampledDepth);
|
||||
if (renderer.raymarchMat != null) CoreUtils.Destroy(renderer.raymarchMat);
|
||||
if (renderer.reprojectMat != null) CoreUtils.Destroy(renderer.reprojectMat);
|
||||
if (renderer.blendAndLightingMat != null) CoreUtils.Destroy(renderer.blendAndLightingMat);
|
||||
if (renderer.depthMat != null) CoreUtils.Destroy(renderer.depthMat);
|
||||
if (renderer.shadowMat != null) CoreUtils.Destroy(renderer.shadowMat);
|
||||
}
|
||||
|
||||
private EnviroVolumetricCloudRenderer GetCloudsRenderer(Camera cam)
|
||||
{
|
||||
foreach (var r in volumetricCloudsRender)
|
||||
if (r.camera == cam) return r;
|
||||
|
||||
return CreateCloudsRenderer(cam);
|
||||
}
|
||||
|
||||
private void SetMatrix(Camera myCam)
|
||||
{
|
||||
#if ENABLE_VR && ENABLE_XR_MODULE
|
||||
if (UnityEngine.XR.XRSettings.enabled && UnityEngine.XR.XRSettings.stereoRenderingMode == UnityEngine.XR.XRSettings.StereoRenderingMode.SinglePassInstanced)
|
||||
{
|
||||
// Both stereo eye inverse view matrices
|
||||
Matrix4x4 left_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Left).inverse;
|
||||
Matrix4x4 right_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Right).inverse;
|
||||
|
||||
// Both stereo eye inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 left_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
|
||||
Matrix4x4 right_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(left_screen_from_view, true).inverse;
|
||||
Matrix4x4 right_view_from_screen = GL.GetGPUProjectionMatrix(right_screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
{
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
right_view_from_screen[1, 1] *= -1;
|
||||
}
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_RightWorldFromView", right_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
Shader.SetGlobalMatrix("_RightViewFromScreen", right_view_from_screen);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Main eye inverse view matrix
|
||||
Matrix4x4 left_world_from_view = myCam.cameraToWorldMatrix;
|
||||
|
||||
// Inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 screen_from_view = myCam.projectionMatrix;
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
}
|
||||
#else
|
||||
// Main eye inverse view matrix
|
||||
Matrix4x4 left_world_from_view = myCam.cameraToWorldMatrix;
|
||||
|
||||
// Inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 screen_from_view = myCam.projectionMatrix;
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e7ac1f0b8835dd49ae0c2334bb590a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,296 @@
|
||||
//Deprecated since 3.3. Please use the custom pass system now!
|
||||
|
||||
/*
|
||||
#if ENVIRO_HDRP
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable, VolumeComponentMenu("Post-processing/Enviro/Effects Renderer (DEPRECATED)")]
|
||||
public class EnviroHDRPRenderer : CustomPostProcessVolumeComponent, IPostProcessComponent
|
||||
{
|
||||
public bool IsActive() => EnviroManager.instance != null;
|
||||
public override CustomPostProcessInjectionPoint injectionPoint => (CustomPostProcessInjectionPoint)0;
|
||||
private Material blitTrough;
|
||||
private List<EnviroVolumetricCloudRenderer> volumetricCloudsRender = new List<EnviroVolumetricCloudRenderer>();
|
||||
private Vector3 floatingPointOriginMod = Vector3.zero;
|
||||
public BoolParameter activated = new(value: true);
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
if (blitTrough == null)
|
||||
blitTrough = new Material(Shader.Find("Hidden/Enviro/BlitTroughHDRP"));
|
||||
}
|
||||
|
||||
public override void Cleanup()
|
||||
{
|
||||
if (blitTrough != null)
|
||||
CoreUtils.Destroy(blitTrough);
|
||||
|
||||
for(int i = 0; i < volumetricCloudsRender.Count; i++)
|
||||
{
|
||||
CleanCloudsRenderer(volumetricCloudsRender[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
|
||||
{
|
||||
//Do nothing
|
||||
if (activated.value == false || !EnviroHelper.CanRenderOnCamera(camera.camera) || camera.camera.cameraType == CameraType.Preview)
|
||||
{
|
||||
blitTrough.SetTexture("_InputTexture", source);
|
||||
CoreUtils.DrawFullScreen(cmd, blitTrough);
|
||||
return;
|
||||
}
|
||||
|
||||
if(EnviroHelper.ResetMatrix(camera.camera))
|
||||
camera.camera.ResetProjectionMatrix();
|
||||
|
||||
EnviroQuality myQuality = EnviroHelper.GetQualityForCamera(camera.camera);
|
||||
|
||||
//Set what to render on this camera.
|
||||
bool renderVolumetricClouds = false;
|
||||
bool renderFog = false;
|
||||
|
||||
if(EnviroManager.instance.Quality != null)
|
||||
{
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
renderVolumetricClouds = myQuality.volumetricCloudsOverride.volumetricClouds;
|
||||
|
||||
if(EnviroManager.instance.Fog != null)
|
||||
renderFog = myQuality.fogOverride.fog;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
renderVolumetricClouds = EnviroManager.instance.VolumetricClouds.settingsQuality.volumetricClouds;
|
||||
|
||||
if(EnviroManager.instance.Fog != null)
|
||||
renderFog = EnviroManager.instance.Fog.Settings.fog;
|
||||
}
|
||||
|
||||
if (EnviroManager.instance.Objects.worldAnchor != null)
|
||||
floatingPointOriginMod = EnviroManager.instance.Objects.worldAnchor.transform.position;
|
||||
else
|
||||
floatingPointOriginMod = Vector3.zero;
|
||||
|
||||
if (renderVolumetricClouds)
|
||||
{
|
||||
//Create us a volumetric clouds renderer if null.
|
||||
if(GetCloudsRenderer(camera.camera) == null)
|
||||
{
|
||||
CreateCloudsRenderer(camera.camera);
|
||||
}
|
||||
}
|
||||
//Set some global matrixes used for all the enviro effects.
|
||||
SetMatrix(camera.camera);
|
||||
|
||||
|
||||
|
||||
//Clouds
|
||||
if(EnviroManager.instance.Fog != null && EnviroManager.instance.VolumetricClouds != null && renderVolumetricClouds && renderFog)
|
||||
{
|
||||
RenderTexture temp1 = RenderTexture.GetTemporary(source.rt.descriptor);
|
||||
RTHandle temp1Handle = RTHandles.Alloc(temp1);
|
||||
|
||||
if(camera.camera.transform.position.y - floatingPointOriginMod.y < EnviroManager.instance.VolumetricClouds.settingsVolume.bottomCloudsHeight)
|
||||
{
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(camera.camera);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera,cmd, source, temp1Handle, renderer, myQuality);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && camera.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
RenderTexture temp2 = RenderTexture.GetTemporary(source.rt.descriptor);
|
||||
RTHandle temp2Handle = RTHandles.Alloc(temp2);
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsHDRP(camera.camera,cmd,temp1Handle,temp2Handle,renderer);
|
||||
EnviroManager.instance.Fog.RenderHeightFogHDRP(camera.camera,cmd,temp2Handle,destination);
|
||||
RenderTexture.ReleaseTemporary(temp2);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFogHDRP(camera.camera,cmd,temp1Handle,destination);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
EnviroManager.instance.Fog.RenderHeightFogHDRP(camera.camera,cmd,source,temp1Handle);
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(camera.camera);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && camera.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
RenderTexture temp2 = RenderTexture.GetTemporary(source.rt.descriptor);
|
||||
RTHandle temp2Handle = RTHandles.Alloc(temp2);
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsHDRP(camera.camera,cmd,temp1Handle,temp2Handle,renderer);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera,cmd, temp2Handle, destination, renderer, myQuality);
|
||||
RenderTexture.ReleaseTemporary(temp2);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera,cmd, temp1Handle, destination, renderer, myQuality);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RenderTexture.ReleaseTemporary(temp1);
|
||||
//temp1Handle.Release();
|
||||
}
|
||||
else if(EnviroManager.instance.VolumetricClouds != null && renderVolumetricClouds && !renderFog)
|
||||
{
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(camera.camera);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && camera.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
RenderTexture temp1 = RenderTexture.GetTemporary(source.rt.descriptor);
|
||||
RTHandle temp1Handle = RTHandles.Alloc(temp1);
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsHDRP(camera.camera,cmd,source,temp1Handle,renderer);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera,cmd, temp1Handle, destination, renderer, myQuality);
|
||||
RenderTexture.ReleaseTemporary(temp1);
|
||||
//temp1Handle.Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsHDRP(camera.camera,cmd, source, destination, renderer, myQuality);
|
||||
}
|
||||
|
||||
}
|
||||
else if (Enviro.EnviroManager.instance.Fog != null && renderFog)
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFogHDRP(camera.camera,cmd,source,destination);
|
||||
}
|
||||
else
|
||||
{
|
||||
blitTrough.SetTexture("_InputTexture", source);
|
||||
CoreUtils.DrawFullScreen(cmd, blitTrough);
|
||||
}
|
||||
|
||||
if(!renderVolumetricClouds)
|
||||
Shader.SetGlobalTexture("_EnviroClouds", Texture2D.blackTexture);
|
||||
|
||||
}
|
||||
|
||||
private EnviroVolumetricCloudRenderer CreateCloudsRenderer(Camera cam)
|
||||
{
|
||||
EnviroVolumetricCloudRenderer r = new EnviroVolumetricCloudRenderer();
|
||||
r.camera = cam;
|
||||
volumetricCloudsRender.Add(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
private void CleanCloudsRenderer(EnviroVolumetricCloudRenderer renderer)
|
||||
{
|
||||
|
||||
if (renderer.fullBuffer != null)
|
||||
{
|
||||
for (int i = 0; i < renderer.fullBuffer.Length; i++)
|
||||
{
|
||||
if (renderer.fullBuffer[i] != null)
|
||||
{
|
||||
CoreUtils.Destroy(renderer.fullBuffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (renderer.undersampleBuffer)
|
||||
{
|
||||
CoreUtils.Destroy(renderer.undersampleBuffer);
|
||||
}
|
||||
|
||||
if (renderer.downsampledDepth)
|
||||
{
|
||||
CoreUtils.Destroy(renderer.downsampledDepth);
|
||||
}
|
||||
|
||||
if(renderer.raymarchMat != null)
|
||||
CoreUtils.Destroy(renderer.raymarchMat);
|
||||
|
||||
if(renderer.reprojectMat != null)
|
||||
CoreUtils.Destroy(renderer.reprojectMat);
|
||||
|
||||
if(renderer.blendAndLightingMat != null)
|
||||
CoreUtils.Destroy(renderer.blendAndLightingMat);
|
||||
|
||||
if(renderer.depthMat != null)
|
||||
CoreUtils.Destroy (renderer.depthMat);
|
||||
|
||||
if(renderer.shadowMat != null)
|
||||
CoreUtils.Destroy (renderer.shadowMat);
|
||||
}
|
||||
|
||||
private EnviroVolumetricCloudRenderer GetCloudsRenderer(Camera cam)
|
||||
{
|
||||
for (int i = 0; i < volumetricCloudsRender.Count; i++)
|
||||
{
|
||||
if(volumetricCloudsRender[i].camera == cam)
|
||||
return volumetricCloudsRender[i];
|
||||
}
|
||||
return CreateCloudsRenderer(cam);
|
||||
}
|
||||
|
||||
private void SetMatrix(Camera myCam)
|
||||
{
|
||||
#if ENABLE_VR && ENABLE_XR_MODULE
|
||||
if (UnityEngine.XR.XRSettings.enabled && UnityEngine.XR.XRSettings.stereoRenderingMode == UnityEngine.XR.XRSettings.StereoRenderingMode.SinglePassInstanced)
|
||||
{
|
||||
// Both stereo eye inverse view matrices
|
||||
Matrix4x4 left_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Left).inverse;
|
||||
Matrix4x4 right_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Right).inverse;
|
||||
|
||||
// Both stereo eye inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 left_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
|
||||
Matrix4x4 right_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(left_screen_from_view, true).inverse;
|
||||
Matrix4x4 right_view_from_screen = GL.GetGPUProjectionMatrix(right_screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
{
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
right_view_from_screen[1, 1] *= -1;
|
||||
}
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_RightWorldFromView", right_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
Shader.SetGlobalMatrix("_RightViewFromScreen", right_view_from_screen);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Main eye inverse view matrix
|
||||
Matrix4x4 left_world_from_view = myCam.cameraToWorldMatrix;
|
||||
|
||||
// Inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 screen_from_view = myCam.projectionMatrix;
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
}
|
||||
#else
|
||||
// Main eye inverse view matrix
|
||||
Matrix4x4 left_world_from_view = myCam.cameraToWorldMatrix;
|
||||
|
||||
// Inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 screen_from_view = myCam.projectionMatrix;
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2f1f84926178344e86b6d5fe65e258f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.2.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/Renderer/EnviroHDRPRenderer.cs
|
||||
uploadId: 766468
|
||||
@@ -0,0 +1,235 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[ImageEffectAllowedInSceneView]
|
||||
public class EnviroRenderer : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Assign a quality here if you want to use different settings for this camera. Otherwise it takes settings from Enviro Manager.")]
|
||||
private EnviroQuality myQuality;
|
||||
private Camera myCam;
|
||||
private EnviroVolumetricCloudRenderer volumetricCloudsRender;
|
||||
private Vector3 floatingPointOriginMod = Vector3.zero;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
myCam = GetComponent<Camera>();
|
||||
|
||||
//Disable this component in URP and HDRP.
|
||||
#if ENVIRO_HDRP || ENVIRO_URP
|
||||
this.enabled = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void OnDisable ()
|
||||
{
|
||||
CleanupVolumetricRenderer();
|
||||
}
|
||||
|
||||
private void CleanupVolumetricRenderer()
|
||||
{
|
||||
if(volumetricCloudsRender != null)
|
||||
{
|
||||
if(volumetricCloudsRender.raymarchMat != null)
|
||||
DestroyImmediate(volumetricCloudsRender.raymarchMat);
|
||||
|
||||
if(volumetricCloudsRender.blendAndLightingMat != null)
|
||||
DestroyImmediate(volumetricCloudsRender.blendAndLightingMat);
|
||||
|
||||
if(volumetricCloudsRender.reprojectMat != null)
|
||||
DestroyImmediate(volumetricCloudsRender.reprojectMat);
|
||||
|
||||
if(volumetricCloudsRender.undersampleBuffer != null)
|
||||
DestroyImmediate(volumetricCloudsRender.undersampleBuffer);
|
||||
|
||||
if(volumetricCloudsRender.fullBuffer != null && volumetricCloudsRender.fullBuffer.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < volumetricCloudsRender.fullBuffer.Length; i++)
|
||||
{
|
||||
if(volumetricCloudsRender.fullBuffer[i] != null)
|
||||
DestroyImmediate(volumetricCloudsRender.fullBuffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetMatrix()
|
||||
{
|
||||
if (myCam.stereoEnabled)
|
||||
{
|
||||
// Both stereo eye inverse view matrices
|
||||
Matrix4x4 left_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Left).inverse;
|
||||
Matrix4x4 right_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Right).inverse;
|
||||
|
||||
// Both stereo eye inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 left_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
|
||||
Matrix4x4 right_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(left_screen_from_view, true).inverse;
|
||||
Matrix4x4 right_view_from_screen = GL.GetGPUProjectionMatrix(right_screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
{
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
right_view_from_screen[1, 1] *= -1;
|
||||
}
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_RightWorldFromView", right_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
Shader.SetGlobalMatrix("_RightViewFromScreen", right_view_from_screen);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Main eye inverse view matrix
|
||||
Matrix4x4 left_world_from_view = myCam.cameraToWorldMatrix;
|
||||
|
||||
// Inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 screen_from_view = myCam.projectionMatrix;
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
|
||||
// Store matrices
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[ImageEffectOpaque]
|
||||
private void OnRenderImage(RenderTexture src, RenderTexture dest)
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
{
|
||||
Graphics.Blit(src,dest);
|
||||
return;
|
||||
}
|
||||
|
||||
if(myCam == null)
|
||||
myCam = GetComponent<Camera>();
|
||||
|
||||
if (myCam.actualRenderingPath == RenderingPath.Forward)
|
||||
myCam.depthTextureMode |= DepthTextureMode.Depth;
|
||||
|
||||
if(EnviroHelper.ResetMatrix(myCam))
|
||||
myCam.ResetProjectionMatrix();
|
||||
|
||||
myQuality = EnviroHelper.GetQualityForCamera(myCam);
|
||||
|
||||
//Set what to render on this camera.
|
||||
bool renderVolumetricClouds = false;
|
||||
bool renderFog = false;
|
||||
|
||||
if(EnviroManager.instance.Quality != null)
|
||||
{
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
renderVolumetricClouds = myQuality.volumetricCloudsOverride.volumetricClouds;
|
||||
|
||||
if(EnviroManager.instance.Fog != null)
|
||||
renderFog = myQuality.fogOverride.fog;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
renderVolumetricClouds = EnviroManager.instance.VolumetricClouds.settingsQuality.volumetricClouds;
|
||||
|
||||
if(EnviroManager.instance.Fog != null)
|
||||
renderFog = EnviroManager.instance.Fog.Settings.fog;
|
||||
}
|
||||
|
||||
if (EnviroManager.instance.Objects.worldAnchor != null)
|
||||
floatingPointOriginMod = EnviroManager.instance.Objects.worldAnchor.transform.position;
|
||||
else
|
||||
floatingPointOriginMod = Vector3.zero;
|
||||
|
||||
////////Rendering//////////
|
||||
SetMatrix();
|
||||
|
||||
if(volumetricCloudsRender == null)
|
||||
volumetricCloudsRender = new EnviroVolumetricCloudRenderer();
|
||||
|
||||
|
||||
volumetricCloudsRender.camera = myCam;
|
||||
|
||||
//Render volumetrics mask first
|
||||
if(EnviroManager.instance.Fog != null && renderFog)
|
||||
EnviroManager.instance.Fog.RenderVolumetrics(myCam, src);
|
||||
|
||||
if(EnviroManager.instance.Fog != null && EnviroManager.instance.VolumetricClouds != null && renderVolumetricClouds && renderFog)
|
||||
{
|
||||
//Change the order of clouds and fog
|
||||
RenderTexture temp = RenderTexture.GetTemporary(src.descriptor);
|
||||
RenderTexture temp2 = RenderTexture.GetTemporary(src.descriptor);
|
||||
|
||||
|
||||
if(myCam.transform.position.y - floatingPointOriginMod.y < EnviroManager.instance.VolumetricClouds.settingsVolume.bottomCloudsHeight)
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricClouds(myCam, src, temp, volumetricCloudsRender, myQuality);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && myCam.cameraType != CameraType.Reflection)
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadows(temp,temp2,volumetricCloudsRender);
|
||||
EnviroManager.instance.Fog.RenderHeightFog(myCam,temp2,dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFog(myCam,temp,dest);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFog(myCam,src,temp);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && myCam.cameraType != CameraType.Reflection)
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadows(temp,temp2,volumetricCloudsRender);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricClouds(myCam,temp2,dest,volumetricCloudsRender,myQuality);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricClouds(myCam,temp,dest,volumetricCloudsRender,myQuality);
|
||||
}
|
||||
}
|
||||
|
||||
RenderTexture.ReleaseTemporary(temp);
|
||||
RenderTexture.ReleaseTemporary(temp2);
|
||||
}
|
||||
else if(EnviroManager.instance.VolumetricClouds != null && renderVolumetricClouds && !renderFog)
|
||||
{
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && myCam.cameraType != CameraType.Reflection)
|
||||
{
|
||||
RenderTexture temp = RenderTexture.GetTemporary(src.descriptor);
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadows(src,temp,volumetricCloudsRender);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricClouds(myCam,temp,dest,volumetricCloudsRender, myQuality);
|
||||
RenderTexture.ReleaseTemporary(temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricClouds(myCam,src,dest,volumetricCloudsRender, myQuality);
|
||||
}
|
||||
|
||||
}
|
||||
else if (Enviro.EnviroManager.instance.Fog != null && renderFog)
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFog(myCam,src,dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
Graphics.Blit(src,dest);
|
||||
}
|
||||
|
||||
if(!renderVolumetricClouds)
|
||||
Shader.SetGlobalTexture("_EnviroClouds", Texture2D.blackTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfd6cec7710802146be56bb22888bf57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/Renderer/EnviroRenderer.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,68 @@
|
||||
#if ENVIRO_URP
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
public class EnviroURPRenderFeature : ScriptableRendererFeature
|
||||
{
|
||||
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
|
||||
private EnviroURPRenderGraph graph;
|
||||
private EnviroURPRenderPass pass;
|
||||
|
||||
public override void Create()
|
||||
{
|
||||
// if(UnityEngine.Rendering.GraphicsSettings.GetRenderPipelineSettings< UnityEngine.Rendering.Universal.RenderGraphSettings>().enableRenderCompatibilityMode)
|
||||
pass = new EnviroURPRenderPass("Enviro Render Pass");
|
||||
|
||||
graph = new EnviroURPRenderGraph();
|
||||
graph.renderPassEvent = RenderPassEvent.BeforeRenderingTransparents;
|
||||
}
|
||||
|
||||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
|
||||
{
|
||||
if(UnityEngine.Rendering.GraphicsSettings.GetRenderPipelineSettings< UnityEngine.Rendering.Universal.RenderGraphSettings>().enableRenderCompatibilityMode)
|
||||
{
|
||||
if(pass != null && EnviroHelper.CanRenderOnCamera(renderingData.cameraData.camera))
|
||||
{
|
||||
pass.scriptableRenderer = renderer;
|
||||
renderer.EnqueuePass(pass);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(graph != null && EnviroHelper.CanRenderOnCamera(renderingData.cameraData.camera))
|
||||
{
|
||||
renderer.EnqueuePass(graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
private EnviroURPRenderPass pass;
|
||||
|
||||
public override void Create()
|
||||
{
|
||||
pass = new EnviroURPRenderPass("Enviro Render Pass");
|
||||
}
|
||||
|
||||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
|
||||
{
|
||||
if(pass != null && EnviroHelper.CanRenderOnCamera(renderingData.cameraData.camera))
|
||||
{
|
||||
pass.scriptableRenderer = renderer;
|
||||
renderer.EnqueuePass(pass);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5beaef983462df4a944c521f9064a91
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/Renderer/EnviroURPRenderFeature.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,359 @@
|
||||
#if ENVIRO_URP && UNITY_6000_0_OR_NEWER
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.RenderGraphModule;
|
||||
|
||||
namespace Enviro {
|
||||
public class EnviroURPRenderGraph : ScriptableRenderPass
|
||||
{
|
||||
public class PassData
|
||||
{
|
||||
internal TextureHandle src;
|
||||
internal TextureHandle target;
|
||||
internal TextureHandle read1;
|
||||
internal TextureHandle read2;
|
||||
internal Vector4 scaleBias;
|
||||
internal string srcName;
|
||||
internal string read1Name;
|
||||
internal string read2Name;
|
||||
internal int pass;
|
||||
internal Material material;
|
||||
}
|
||||
|
||||
private Vector4 m_ScaleBias = new Vector4(1f, 1f, 0f, 0f);
|
||||
private List<EnviroVolumetricCloudRenderer> volumetricCloudsRender = new List<EnviroVolumetricCloudRenderer>();
|
||||
|
||||
private Material blitThroughMat, fogMat;
|
||||
private Vector3 floatingPointOriginMod = Vector3.zero;
|
||||
|
||||
private EnviroVolumetricCloudRenderer CreateCloudsRenderer(Camera cam)
|
||||
{
|
||||
EnviroVolumetricCloudRenderer r = new EnviroVolumetricCloudRenderer();
|
||||
r.camera = cam;
|
||||
volumetricCloudsRender.Add(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
private EnviroVolumetricCloudRenderer GetCloudsRenderer(Camera cam)
|
||||
{
|
||||
for (int i = 0; i < volumetricCloudsRender.Count; i++)
|
||||
{
|
||||
if(volumetricCloudsRender[i].camera == cam)
|
||||
return volumetricCloudsRender[i];
|
||||
}
|
||||
return CreateCloudsRenderer(cam);
|
||||
}
|
||||
|
||||
|
||||
public void Blit (string passName, RenderGraph renderGraph, Material mat, TextureHandle src, TextureHandle target, int pass)
|
||||
{
|
||||
using (var builder = renderGraph.AddRasterRenderPass<PassData>(passName, out var passData))
|
||||
{
|
||||
passData.src = src;
|
||||
passData.target = target;
|
||||
passData.material = mat;
|
||||
passData.pass = pass;
|
||||
passData.scaleBias = m_ScaleBias;
|
||||
passData.srcName = "_MainTex";
|
||||
|
||||
builder.UseTexture(passData.src,AccessFlags.Read);
|
||||
builder.SetRenderAttachment(passData.target, 0);
|
||||
//builder.AllowPassCulling(false);
|
||||
|
||||
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
|
||||
{
|
||||
if(data.src.IsValid())
|
||||
data.material.SetTexture(data.srcName, data.src);
|
||||
|
||||
Blitter.BlitTexture(context.cmd, data.scaleBias, data.material, data.pass);
|
||||
});
|
||||
}
|
||||
}
|
||||
public void Blit (string passName, RenderGraph renderGraph, Material mat, TextureHandle src, TextureHandle target, int pass, TextureHandle read1, string read1Name)
|
||||
{
|
||||
using (var builder = renderGraph.AddRasterRenderPass<PassData>(passName, out var passData))
|
||||
{
|
||||
passData.src = src;
|
||||
passData.target = target;
|
||||
passData.read1 = read1;
|
||||
passData.read1Name = read1Name;
|
||||
passData.material = mat;
|
||||
passData.pass = pass;
|
||||
passData.scaleBias = m_ScaleBias;
|
||||
passData.srcName = "_MainTex";
|
||||
|
||||
|
||||
builder.UseTexture(passData.src,AccessFlags.Read);
|
||||
builder.UseTexture(passData.read1,AccessFlags.Read);
|
||||
//builder.SetInputAttachment(read1,0);
|
||||
builder.SetRenderAttachment(passData.target, 0);
|
||||
//builder.AllowPassCulling(false);
|
||||
|
||||
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
|
||||
{
|
||||
if(data.src.IsValid())
|
||||
data.material.SetTexture(data.srcName, data.src);
|
||||
|
||||
if(data.read1.IsValid())
|
||||
data.material.SetTexture(data.read1Name, data.read1);
|
||||
|
||||
Blitter.BlitTexture(context.cmd,data.scaleBias, data.material, data.pass);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Blit (string passName, RenderGraph renderGraph, Material mat, TextureHandle src, TextureHandle target, int pass,TextureHandle read1, string read1Name,TextureHandle read2, string read2Name)
|
||||
{
|
||||
using (var builder = renderGraph.AddRasterRenderPass<PassData>(passName, out var passData))
|
||||
{
|
||||
passData.src = src;
|
||||
passData.target = target;
|
||||
passData.read1 = read1;
|
||||
passData.read1Name = read1Name;
|
||||
passData.read2 = read2;
|
||||
passData.read2Name = read2Name;
|
||||
passData.material = mat;
|
||||
passData.pass = pass;
|
||||
passData.scaleBias = m_ScaleBias;
|
||||
passData.srcName = "_MainTex";
|
||||
|
||||
|
||||
|
||||
builder.UseTexture(passData.src,AccessFlags.Read);
|
||||
builder.UseTexture(passData.read1,AccessFlags.Read);
|
||||
builder.UseTexture(passData.read2,AccessFlags.Read);
|
||||
//builder.SetInputAttachment(read1,0);
|
||||
builder.SetRenderAttachment(passData.target, 0);
|
||||
//builder.AllowPassCulling(false);
|
||||
|
||||
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
|
||||
{
|
||||
if(data.src.IsValid())
|
||||
data.material.SetTexture(data.srcName, data.src);
|
||||
|
||||
if(data.read1.IsValid())
|
||||
data.material.SetTexture(data.read1Name, data.read1);
|
||||
|
||||
if(data.read2.IsValid())
|
||||
data.material.SetTexture(data.read2Name, data.read2);
|
||||
|
||||
Blitter.BlitTexture(context.cmd, data.scaleBias, data.material, data.pass);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SetMatrix(Camera myCam)
|
||||
{
|
||||
#if ENABLE_VR || ENABLE_XR_MODULE
|
||||
if (UnityEngine.XR.XRSettings.enabled && UnityEngine.XR.XRSettings.stereoRenderingMode == UnityEngine.XR.XRSettings.StereoRenderingMode.SinglePassInstanced && myCam.stereoEnabled)
|
||||
{
|
||||
// Both stereo eye inverse view matrices
|
||||
Matrix4x4 left_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Left).inverse;
|
||||
Matrix4x4 right_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Right).inverse;
|
||||
|
||||
// Both stereo eye inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 left_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
|
||||
Matrix4x4 right_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(left_screen_from_view, true).inverse;
|
||||
Matrix4x4 right_view_from_screen = GL.GetGPUProjectionMatrix(right_screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
{
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
right_view_from_screen[1, 1] *= -1;
|
||||
}
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_RightWorldFromView", right_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
Shader.SetGlobalMatrix("_RightViewFromScreen", right_view_from_screen);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Main eye inverse view matrix
|
||||
Matrix4x4 left_world_from_view = myCam.cameraToWorldMatrix;
|
||||
|
||||
// Inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 screen_from_view = myCam.projectionMatrix;
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
}
|
||||
#else
|
||||
// Main eye inverse view matrix
|
||||
Matrix4x4 left_world_from_view = myCam.cameraToWorldMatrix;
|
||||
|
||||
// Inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 screen_from_view = myCam.projectionMatrix;
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
#endif
|
||||
}
|
||||
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
|
||||
{
|
||||
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
|
||||
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
|
||||
|
||||
|
||||
if(EnviroHelper.ResetMatrix(cameraData.camera))
|
||||
cameraData.camera.ResetProjectionMatrix();
|
||||
|
||||
EnviroQuality myQuality = EnviroHelper.GetQualityForCamera(cameraData.camera);
|
||||
|
||||
//Set what to render on this camera.
|
||||
bool renderVolumetricClouds = false;
|
||||
bool renderFog = false;
|
||||
|
||||
if(EnviroManager.instance.Quality != null)
|
||||
{
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
renderVolumetricClouds = myQuality.volumetricCloudsOverride.volumetricClouds;
|
||||
|
||||
if(EnviroManager.instance.Fog != null)
|
||||
renderFog = myQuality.fogOverride.fog;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
renderVolumetricClouds = EnviroManager.instance.VolumetricClouds.settingsQuality.volumetricClouds;
|
||||
|
||||
if(EnviroManager.instance.Fog != null)
|
||||
renderFog = EnviroManager.instance.Fog.Settings.fog;
|
||||
}
|
||||
|
||||
if (EnviroManager.instance.Objects.worldAnchor != null)
|
||||
floatingPointOriginMod = EnviroManager.instance.Objects.worldAnchor.transform.position;
|
||||
else
|
||||
floatingPointOriginMod = Vector3.zero;
|
||||
|
||||
//Set some global matrixes used for all the enviro effects.
|
||||
SetMatrix(cameraData.camera);
|
||||
|
||||
RenderTextureDescriptor desc = cameraData.cameraTargetDescriptor;
|
||||
desc.colorFormat = RenderTextureFormat.ARGBHalf;
|
||||
desc.msaaSamples = 1;
|
||||
desc.depthBufferBits = 0;
|
||||
|
||||
TextureHandle source = UniversalRenderer.CreateRenderGraphTexture(renderGraph, desc, "CopyTexture", false);
|
||||
TextureHandle target = resourceData.activeColorTexture;
|
||||
|
||||
if(blitThroughMat == null)
|
||||
blitThroughMat = new Material(Shader.Find("Hidden/EnviroBlitThroughURP17"));
|
||||
|
||||
// This check is to avoid an error from the material preview in the scene
|
||||
if (!target.IsValid() || !source.IsValid())
|
||||
return;
|
||||
|
||||
//Blit Main Texture
|
||||
using ( var builder = renderGraph.AddRasterRenderPass<PassData>("Enviro 3 Copy Texture", out var passData))
|
||||
{
|
||||
passData.src = target;
|
||||
passData.target = source;
|
||||
passData.material = blitThroughMat;
|
||||
passData.scaleBias = m_ScaleBias;
|
||||
|
||||
|
||||
builder.UseTexture(passData.src);
|
||||
builder.SetRenderAttachment(passData.target, 0);
|
||||
|
||||
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
|
||||
{
|
||||
data.material.SetTexture("_MainTex", data.src);
|
||||
Blitter.BlitTexture(context.cmd, data.scaleBias, data.material, 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//Render volumetrics mask first
|
||||
if(EnviroManager.instance.Fog != null && renderFog)
|
||||
EnviroManager.instance.Fog.RenderVolumetricsURP(this,renderGraph,resourceData,cameraData,source);
|
||||
|
||||
if(EnviroManager.instance.Fog != null && EnviroManager.instance.VolumetricClouds != null && renderVolumetricClouds && renderFog)
|
||||
{
|
||||
TextureHandle temp1 = UniversalRenderer.CreateRenderGraphTexture(renderGraph, desc, "Temp1", false);
|
||||
|
||||
if(cameraData.camera.transform.position.y - floatingPointOriginMod.y < EnviroManager.instance.VolumetricClouds.settingsVolume.bottomCloudsHeight)
|
||||
{
|
||||
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(cameraData.camera);
|
||||
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(this,renderGraph, resourceData, cameraData,source,temp1, renderer, myQuality);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && cameraData.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
TextureHandle temp2 = UniversalRenderer.CreateRenderGraphTexture(renderGraph, desc, "Temp2", false);
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsURP(this,renderGraph, resourceData, cameraData,temp1,temp2, renderer);
|
||||
EnviroManager.instance.Fog.RenderHeightFogURP(this, renderGraph,resourceData,cameraData,temp2,resourceData.activeColorTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFogURP(this, renderGraph,resourceData,cameraData,temp1,resourceData.activeColorTexture);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFogURP(this, renderGraph,resourceData,cameraData,source,temp1);
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(cameraData.camera);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && cameraData.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
TextureHandle temp2 = UniversalRenderer.CreateRenderGraphTexture(renderGraph, desc, "Temp2", false);
|
||||
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsURP(this,renderGraph, resourceData, cameraData,temp1,temp2, renderer);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(this,renderGraph, resourceData, cameraData,temp2,resourceData.activeColorTexture, renderer, myQuality);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(this,renderGraph, resourceData, cameraData,temp1,resourceData.activeColorTexture, renderer, myQuality);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(EnviroManager.instance.VolumetricClouds != null && renderVolumetricClouds && !renderFog)
|
||||
{
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(cameraData.camera);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && cameraData.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
TextureHandle temp1 = UniversalRenderer.CreateRenderGraphTexture(renderGraph, desc, "Temp1", false);
|
||||
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsURP(this,renderGraph, resourceData, cameraData,source,temp1, renderer);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(this,renderGraph, resourceData, cameraData,temp1,resourceData.activeColorTexture, renderer, myQuality);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(this,renderGraph, resourceData, cameraData,source,resourceData.activeColorTexture, renderer, myQuality);
|
||||
}
|
||||
}
|
||||
else if (EnviroManager.instance.Fog != null && renderFog)
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFogURP(this, renderGraph,resourceData,cameraData,source,resourceData.activeColorTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 193b426f7fef4dc459bfc73b17a3b4d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.6b
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/Renderer/EnviroURPRenderGraph.cs
|
||||
uploadId: 680182
|
||||
@@ -0,0 +1,306 @@
|
||||
#if ENVIRO_URP
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
public class EnviroURPRenderPass : ScriptableRenderPass
|
||||
{
|
||||
public ScriptableRenderer scriptableRenderer { get; set; }
|
||||
|
||||
private Material blitThroughMat;
|
||||
private string pName;
|
||||
|
||||
private List<EnviroVolumetricCloudRenderer> volumetricCloudsRender = new List<EnviroVolumetricCloudRenderer>();
|
||||
private Vector3 floatingPointOriginMod = Vector3.zero;
|
||||
|
||||
public EnviroURPRenderPass (string name)
|
||||
{
|
||||
renderPassEvent = RenderPassEvent.BeforeRenderingTransparents - 1;
|
||||
pName = name;
|
||||
}
|
||||
|
||||
public void CustomBlit(CommandBuffer cmd,Matrix4x4 matrix, RenderTargetIdentifier source, RenderTargetIdentifier target, Material mat, int pass)
|
||||
{
|
||||
cmd.SetGlobalTexture("_MainTex", source);
|
||||
cmd.SetRenderTarget(target, 0, CubemapFace.Unknown, -1);
|
||||
cmd.DrawMesh(RenderingUtils.fullscreenMesh, matrix, mat,0, pass);
|
||||
}
|
||||
|
||||
public void CustomBlit(CommandBuffer cmd,Matrix4x4 matrix, RenderTargetIdentifier source, RenderTargetIdentifier target, Material mat)
|
||||
{
|
||||
cmd.SetGlobalTexture("_MainTex", source);
|
||||
cmd.SetRenderTarget(target, 0, CubemapFace.Unknown, -1);
|
||||
cmd.DrawMesh(RenderingUtils.fullscreenMesh, matrix, mat,0);
|
||||
}
|
||||
|
||||
public void CustomBlit(CommandBuffer cmd,Matrix4x4 matrix, RenderTargetIdentifier source, RenderTargetIdentifier target)
|
||||
{
|
||||
if(blitThroughMat == null)
|
||||
blitThroughMat = new Material(Shader.Find("Hidden/EnviroBlitThrough"));
|
||||
|
||||
cmd.SetGlobalTexture("_MainTex", source);
|
||||
cmd.SetRenderTarget(target, 0, CubemapFace.Unknown, -1);
|
||||
cmd.DrawMesh(RenderingUtils.fullscreenMesh, matrix, blitThroughMat);
|
||||
}
|
||||
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
public void CustomBlit(CommandBuffer cmd,RTHandle source, RTHandle target, Material mat)
|
||||
{
|
||||
Blitter.BlitCameraTexture(cmd,source,target,mat,0);
|
||||
}
|
||||
|
||||
public void CustomBlit(CommandBuffer cmd,RTHandle source, RTHandle target, Material mat, int pass)
|
||||
{
|
||||
Blitter.BlitCameraTexture(cmd,source,target,mat,pass);
|
||||
}
|
||||
|
||||
public void CustomBlit(CommandBuffer cmd,RTHandle source, RTHandle target)
|
||||
{
|
||||
Blitter.BlitCameraTexture(cmd,source,target);
|
||||
}
|
||||
#endif
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
[System.Obsolete]
|
||||
#endif
|
||||
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
|
||||
{
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
ConfigureTarget(scriptableRenderer.cameraColorTargetHandle);
|
||||
#else
|
||||
ConfigureTarget(scriptableRenderer.cameraColorTarget);
|
||||
#endif
|
||||
ConfigureInput(ScriptableRenderPassInput.Depth);
|
||||
}
|
||||
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
[System.Obsolete]
|
||||
#endif
|
||||
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
|
||||
{
|
||||
if(GetCloudsRenderer(renderingData.cameraData.camera) == null)
|
||||
{
|
||||
CreateCloudsRenderer(renderingData.cameraData.camera);
|
||||
}
|
||||
}
|
||||
|
||||
private EnviroVolumetricCloudRenderer CreateCloudsRenderer(Camera cam)
|
||||
{
|
||||
EnviroVolumetricCloudRenderer r = new EnviroVolumetricCloudRenderer();
|
||||
r.camera = cam;
|
||||
volumetricCloudsRender.Add(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
private EnviroVolumetricCloudRenderer GetCloudsRenderer(Camera cam)
|
||||
{
|
||||
for (int i = 0; i < volumetricCloudsRender.Count; i++)
|
||||
{
|
||||
if(volumetricCloudsRender[i].camera == cam)
|
||||
return volumetricCloudsRender[i];
|
||||
}
|
||||
return CreateCloudsRenderer(cam);
|
||||
}
|
||||
|
||||
private void SetMatrix(Camera myCam)
|
||||
{
|
||||
#if ENABLE_VR || ENABLE_XR_MODULE
|
||||
if (UnityEngine.XR.XRSettings.enabled && UnityEngine.XR.XRSettings.stereoRenderingMode == UnityEngine.XR.XRSettings.StereoRenderingMode.SinglePassInstanced && myCam.stereoEnabled)
|
||||
{
|
||||
// Both stereo eye inverse view matrices
|
||||
Matrix4x4 left_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Left).inverse;
|
||||
Matrix4x4 right_world_from_view = myCam.GetStereoViewMatrix(Camera.StereoscopicEye.Right).inverse;
|
||||
|
||||
// Both stereo eye inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 left_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
|
||||
Matrix4x4 right_screen_from_view = myCam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(left_screen_from_view, true).inverse;
|
||||
Matrix4x4 right_view_from_screen = GL.GetGPUProjectionMatrix(right_screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
{
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
right_view_from_screen[1, 1] *= -1;
|
||||
}
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_RightWorldFromView", right_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
Shader.SetGlobalMatrix("_RightViewFromScreen", right_view_from_screen);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Main eye inverse view matrix
|
||||
Matrix4x4 left_world_from_view = myCam.cameraToWorldMatrix;
|
||||
|
||||
// Inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 screen_from_view = myCam.projectionMatrix;
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
}
|
||||
#else
|
||||
// Main eye inverse view matrix
|
||||
Matrix4x4 left_world_from_view = myCam.cameraToWorldMatrix;
|
||||
|
||||
// Inverse projection matrices, plumbed through GetGPUProjectionMatrix to compensate for render texture
|
||||
Matrix4x4 screen_from_view = myCam.projectionMatrix;
|
||||
Matrix4x4 left_view_from_screen = GL.GetGPUProjectionMatrix(screen_from_view, true).inverse;
|
||||
|
||||
// Negate [1,1] to reflect Unity's CBuffer state
|
||||
if (SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
|
||||
left_view_from_screen[1, 1] *= -1;
|
||||
|
||||
Shader.SetGlobalMatrix("_LeftWorldFromView", left_world_from_view);
|
||||
Shader.SetGlobalMatrix("_LeftViewFromScreen", left_view_from_screen);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
[System.Obsolete]
|
||||
#endif
|
||||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
CommandBuffer cmd = CommandBufferPool.Get(pName);
|
||||
|
||||
if(EnviroHelper.ResetMatrix(renderingData.cameraData.camera))
|
||||
renderingData.cameraData.camera.ResetProjectionMatrix();
|
||||
|
||||
EnviroQuality myQuality = EnviroHelper.GetQualityForCamera(renderingData.cameraData.camera);
|
||||
|
||||
//Set what to render on this camera.
|
||||
bool renderVolumetricClouds = false;
|
||||
bool renderFog = false;
|
||||
|
||||
if(EnviroManager.instance.Quality != null)
|
||||
{
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
renderVolumetricClouds = myQuality.volumetricCloudsOverride.volumetricClouds;
|
||||
|
||||
if(EnviroManager.instance.Fog != null)
|
||||
renderFog = myQuality.fogOverride.fog;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
renderVolumetricClouds = EnviroManager.instance.VolumetricClouds.settingsQuality.volumetricClouds;
|
||||
|
||||
if(EnviroManager.instance.Fog != null)
|
||||
renderFog = EnviroManager.instance.Fog.Settings.fog;
|
||||
}
|
||||
|
||||
if (EnviroManager.instance.Objects.worldAnchor != null)
|
||||
floatingPointOriginMod = EnviroManager.instance.Objects.worldAnchor.transform.position;
|
||||
else
|
||||
floatingPointOriginMod = Vector3.zero;
|
||||
|
||||
//Set some global matrixes used for all the enviro effects.
|
||||
SetMatrix(renderingData.cameraData.camera);
|
||||
|
||||
//Create temporary texture and blit the camera content.
|
||||
RenderTexture sourceTemp = RenderTexture.GetTemporary(renderingData.cameraData.cameraTargetDescriptor);
|
||||
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
RenderTargetIdentifier cameraColorTarget = scriptableRenderer.cameraColorTargetHandle.nameID;
|
||||
#else
|
||||
RenderTargetIdentifier cameraColorTarget = scriptableRenderer.cameraColorTarget;
|
||||
#endif
|
||||
|
||||
CustomBlit(cmd, Matrix4x4.identity,cameraColorTarget, new RenderTargetIdentifier(sourceTemp));
|
||||
|
||||
//Render volumetrics mask first
|
||||
if(EnviroManager.instance.Fog != null && renderFog)
|
||||
EnviroManager.instance.Fog.RenderVolumetricsURP(renderingData.cameraData.camera,this,cmd,sourceTemp);
|
||||
|
||||
if(EnviroManager.instance.Fog != null && EnviroManager.instance.VolumetricClouds != null && renderVolumetricClouds && renderFog)
|
||||
{
|
||||
RenderTexture temp1 = RenderTexture.GetTemporary(renderingData.cameraData.cameraTargetDescriptor);
|
||||
|
||||
if(renderingData.cameraData.camera.transform.position.y - floatingPointOriginMod.y < EnviroManager.instance.VolumetricClouds.settingsVolume.bottomCloudsHeight)
|
||||
{
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(renderingData.cameraData.camera);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(renderingData,this,cmd, sourceTemp, temp1, renderer, myQuality);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && renderingData.cameraData.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
RenderTexture temp2 = RenderTexture.GetTemporary(renderingData.cameraData.cameraTargetDescriptor);
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsURP(this,renderingData.cameraData.camera,cmd,temp1,temp2,renderer);
|
||||
EnviroManager.instance.Fog.RenderHeightFogURP(renderingData.cameraData.camera,this,cmd,temp2,cameraColorTarget);
|
||||
RenderTexture.ReleaseTemporary(temp2);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFogURP(renderingData.cameraData.camera,this,cmd,temp1,cameraColorTarget);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFogURP(renderingData.cameraData.camera,this,cmd,sourceTemp,temp1);
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(renderingData.cameraData.camera);
|
||||
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && renderingData.cameraData.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
RenderTexture temp2 = RenderTexture.GetTemporary(renderingData.cameraData.cameraTargetDescriptor);
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsURP(this,renderingData.cameraData.camera,cmd,temp1,temp2,renderer);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(renderingData,this,cmd, temp2, cameraColorTarget, renderer, myQuality);
|
||||
RenderTexture.ReleaseTemporary(temp2);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(renderingData,this,cmd, temp1, cameraColorTarget, renderer, myQuality);
|
||||
}
|
||||
}
|
||||
|
||||
context.ExecuteCommandBuffer(cmd);
|
||||
RenderTexture.ReleaseTemporary(temp1);
|
||||
}
|
||||
else if(EnviroManager.instance.VolumetricClouds != null && renderVolumetricClouds && !renderFog)
|
||||
{
|
||||
EnviroVolumetricCloudRenderer renderer = GetCloudsRenderer(renderingData.cameraData.camera);
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds.settingsGlobal.cloudShadows && renderingData.cameraData.camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
RenderTexture temp1 = RenderTexture.GetTemporary(renderingData.cameraData.cameraTargetDescriptor);
|
||||
EnviroManager.instance.VolumetricClouds.RenderCloudsShadowsURP(this,renderingData.cameraData.camera,cmd,sourceTemp,temp1,renderer);
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(renderingData,this,cmd, temp1, cameraColorTarget, renderer, myQuality);
|
||||
RenderTexture.ReleaseTemporary(temp1);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.RenderVolumetricCloudsURP(renderingData,this,cmd, sourceTemp, cameraColorTarget, renderer, myQuality);
|
||||
}
|
||||
context.ExecuteCommandBuffer(cmd);
|
||||
|
||||
}
|
||||
else if (Enviro.EnviroManager.instance.Fog != null && renderFog)
|
||||
{
|
||||
EnviroManager.instance.Fog.RenderHeightFogURP(renderingData.cameraData.camera,this,cmd,sourceTemp,cameraColorTarget);
|
||||
context.ExecuteCommandBuffer(cmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Render Nothing
|
||||
}
|
||||
|
||||
if(!renderVolumetricClouds)
|
||||
Shader.SetGlobalTexture("_EnviroClouds", Texture2D.blackTexture);
|
||||
|
||||
//Release source temp render texture
|
||||
CommandBufferPool.Release(cmd);
|
||||
RenderTexture.ReleaseTemporary(sourceTemp);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 292862f9353b76e49b5f983de89d59b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Base/Renderer/EnviroURPRenderPass.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Enviro3.Runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:15fc0a57446b3144c949da3e2b9737a9",
|
||||
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
|
||||
"GUID:457756d89b35d2941b3e7b37b4ece6f1"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8990947d903fec847b19d9f51781afb1
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Enviro3.Runtime.asmdef
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8d64b536c5fa1148b7d0876d6e6ec8f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8e4f90f9f6fddf4c9dd3295d72da4ff
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,275 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroAudio
|
||||
{
|
||||
public List<EnviroAudioClip> ambientClips = new List<EnviroAudioClip>();
|
||||
public List<EnviroAudioClip> weatherClips = new List<EnviroAudioClip>();
|
||||
public List<EnviroAudioClip> thunderClips = new List<EnviroAudioClip>();
|
||||
public float ambientMasterVolume = 1f;
|
||||
public float weatherMasterVolume = 1f;
|
||||
public float thunderMasterVolume = 1f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroAudioClip
|
||||
{
|
||||
public enum PlayBackType
|
||||
{
|
||||
Always,
|
||||
BasedOnSun,
|
||||
BasedOnMoon
|
||||
}
|
||||
|
||||
public bool showEditor;
|
||||
public string name;
|
||||
public AudioClip audioClip;
|
||||
public UnityEngine.Audio.AudioMixerGroup audioMixerGroup;
|
||||
public PlayBackType playBackType;
|
||||
public AudioSource myAudioSource;
|
||||
public bool loop = false;
|
||||
public float volume = 0f;
|
||||
public AnimationCurve volumeCurve = new AnimationCurve();
|
||||
public float maxVolume = 1f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[ExecuteInEditMode]
|
||||
public class EnviroAudioModule : EnviroModule
|
||||
{
|
||||
public Enviro.EnviroAudio Settings;
|
||||
public EnviroAudioModule preset;
|
||||
|
||||
public float ambientVolumeModifier, weatherVolumeModifier, thunderVolumeModifier = 0f;
|
||||
|
||||
//Inspector
|
||||
public bool showAmbientSetupControls,showWeatherSetupControls,showThunderSetupControls, showAudioControls;
|
||||
|
||||
public override void Enable ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
CreateAudio();
|
||||
}
|
||||
|
||||
public override void Disable ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
private void Setup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance.Objects.audio != null)
|
||||
EnviroHelper.DestroyExtended(EnviroManager.instance.Objects.audio);
|
||||
}
|
||||
|
||||
|
||||
// Update Method
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
if(!active)
|
||||
return;
|
||||
|
||||
UpdateAudio();
|
||||
}
|
||||
|
||||
public void CreateAudio()
|
||||
{
|
||||
|
||||
if(EnviroManager.instance.Objects.audio != null)
|
||||
{
|
||||
EnviroHelper.DestroyExtended(EnviroManager.instance.Objects.audio);
|
||||
EnviroManager.instance.Objects.audio = null;
|
||||
}
|
||||
|
||||
if(EnviroManager.instance.Objects.audio == null)
|
||||
{
|
||||
EnviroManager.instance.Objects.audio = new GameObject();
|
||||
EnviroManager.instance.Objects.audio.hideFlags = HideFlags.DontSave;
|
||||
EnviroManager.instance.Objects.audio.name = "Audio";
|
||||
EnviroManager.instance.Objects.audio.transform.SetParent(EnviroManager.instance.transform);
|
||||
EnviroManager.instance.Objects.audio.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
//Ambient
|
||||
for(int i = 0; i < Settings.ambientClips.Count; i++)
|
||||
{
|
||||
if(Settings.ambientClips[i].myAudioSource != null)
|
||||
EnviroHelper.DestroyExtended(Settings.ambientClips[i].myAudioSource.gameObject);
|
||||
|
||||
GameObject sys;
|
||||
|
||||
if(Settings.ambientClips[i].audioClip != null)
|
||||
{
|
||||
sys = new GameObject();
|
||||
sys.name = "Ambient - " +Settings.ambientClips[i].name;
|
||||
sys.transform.SetParent(EnviroManager.instance.Objects.audio.transform);
|
||||
Settings.ambientClips[i].myAudioSource = sys.AddComponent<AudioSource>();
|
||||
Settings.ambientClips[i].myAudioSource.clip = Settings.ambientClips[i].audioClip;
|
||||
Settings.ambientClips[i].myAudioSource.loop = Settings.ambientClips[i].loop;
|
||||
Settings.ambientClips[i].myAudioSource.volume = Settings.ambientClips[i].volume;
|
||||
Settings.ambientClips[i].myAudioSource.outputAudioMixerGroup = Settings.ambientClips[i].audioMixerGroup;
|
||||
}
|
||||
}
|
||||
|
||||
//Weather
|
||||
for(int i = 0; i < Settings.weatherClips.Count; i++)
|
||||
{
|
||||
if(Settings.weatherClips[i].myAudioSource != null)
|
||||
EnviroHelper.DestroyExtended(Settings.weatherClips[i].myAudioSource.gameObject);
|
||||
|
||||
GameObject sys;
|
||||
|
||||
if(Settings.weatherClips[i].audioClip != null)
|
||||
{
|
||||
sys = new GameObject();
|
||||
sys.name = "Weather - " + Settings.weatherClips[i].name;
|
||||
sys.transform.SetParent(EnviroManager.instance.Objects.audio.transform);
|
||||
Settings.weatherClips[i].myAudioSource = sys.AddComponent<AudioSource>();
|
||||
Settings.weatherClips[i].myAudioSource.clip = Settings.weatherClips[i].audioClip;
|
||||
Settings.weatherClips[i].myAudioSource.loop = Settings.weatherClips[i].loop;
|
||||
Settings.weatherClips[i].myAudioSource.volume = Settings.weatherClips[i].volume;
|
||||
Settings.weatherClips[i].myAudioSource.outputAudioMixerGroup = Settings.weatherClips[i].audioMixerGroup;
|
||||
}
|
||||
}
|
||||
|
||||
//Tunder
|
||||
for(int i = 0; i < Settings.thunderClips.Count; i++)
|
||||
{
|
||||
if(Settings.thunderClips[i].myAudioSource != null)
|
||||
EnviroHelper.DestroyExtended(Settings.thunderClips[i].myAudioSource.gameObject);
|
||||
|
||||
GameObject sys;
|
||||
|
||||
if(Settings.thunderClips[i].audioClip != null)
|
||||
{
|
||||
sys = new GameObject();
|
||||
sys.name = "Thunder - " + Settings.thunderClips[i].name;
|
||||
sys.transform.SetParent(EnviroManager.instance.Objects.audio.transform);
|
||||
Settings.thunderClips[i].myAudioSource = sys.AddComponent<AudioSource>();
|
||||
Settings.thunderClips[i].myAudioSource.clip = Settings.thunderClips[i].audioClip;
|
||||
Settings.thunderClips[i].myAudioSource.loop = false;
|
||||
Settings.thunderClips[i].myAudioSource.playOnAwake = false;
|
||||
Settings.thunderClips[i].myAudioSource.volume = Settings.thunderClips[i].volume;
|
||||
Settings.thunderClips[i].myAudioSource.outputAudioMixerGroup = Settings.thunderClips[i].audioMixerGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Plays random thunder SFX audio.
|
||||
public void PlayRandomThunderSFX()
|
||||
{
|
||||
int thunderSFX = UnityEngine.Random.Range(0,Settings.thunderClips.Count);
|
||||
|
||||
if(Settings.thunderClips.Count > 0 && Settings.thunderClips[thunderSFX] != null)
|
||||
{
|
||||
Settings.thunderClips[thunderSFX].myAudioSource.volume = Settings.thunderClips[thunderSFX].volume * Settings.thunderMasterVolume + thunderVolumeModifier;
|
||||
Settings.thunderClips[thunderSFX].myAudioSource.PlayOneShot(Settings.thunderClips[thunderSFX].myAudioSource.clip);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAudio()
|
||||
{
|
||||
for(int i = 0; i < Settings.ambientClips.Count; i++)
|
||||
{
|
||||
UpdateEnviroAudioClip(Settings.ambientClips[i],Settings.ambientMasterVolume + ambientVolumeModifier);
|
||||
}
|
||||
|
||||
for(int i = 0; i < Settings.weatherClips.Count; i++)
|
||||
{
|
||||
UpdateEnviroAudioClip(Settings.weatherClips[i],Settings.weatherMasterVolume + weatherVolumeModifier);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateEnviroAudioClip(EnviroAudioClip clip, float masterVolume)
|
||||
{
|
||||
if(clip.audioClip != null && clip.myAudioSource != null)
|
||||
{
|
||||
if(!Application.isPlaying)
|
||||
{
|
||||
clip.myAudioSource.Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
clip.myAudioSource.loop = clip.loop;
|
||||
|
||||
switch (clip.playBackType)
|
||||
{
|
||||
case EnviroAudioClip.PlayBackType.Always:
|
||||
clip.myAudioSource.volume = clip.volume * masterVolume;
|
||||
break;
|
||||
|
||||
case EnviroAudioClip.PlayBackType.BasedOnSun:
|
||||
clip.myAudioSource.volume = clip.volumeCurve.Evaluate(EnviroManager.instance.solarTime);
|
||||
clip.myAudioSource.volume *= clip.volume * masterVolume;
|
||||
break;
|
||||
|
||||
case EnviroAudioClip.PlayBackType.BasedOnMoon:
|
||||
clip.myAudioSource.volume = clip.volumeCurve.Evaluate(EnviroManager.instance.lunarTime);
|
||||
clip.myAudioSource.volume *= clip.volume * masterVolume;
|
||||
break;
|
||||
}
|
||||
|
||||
//Enable or disable playback based on volume
|
||||
if(clip.myAudioSource.volume < 0.001f && clip.myAudioSource.isPlaying)
|
||||
clip.myAudioSource.Stop();
|
||||
|
||||
if(clip.myAudioSource.volume > 0f && !clip.myAudioSource.isPlaying)
|
||||
clip.myAudioSource.Play();
|
||||
}
|
||||
}
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
Settings = JsonUtility.FromJson<Enviro.EnviroAudio>(JsonUtility.ToJson(preset.Settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroAudioModule t = ScriptableObject.CreateInstance<EnviroAudioModule>();
|
||||
t.name = "Audio Module";
|
||||
t.Settings = JsonUtility.FromJson<Enviro.EnviroAudio>(JsonUtility.ToJson(Settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SaveModuleValues (EnviroAudioModule module)
|
||||
{
|
||||
module.Settings = JsonUtility.FromJson<Enviro.EnviroAudio>(JsonUtility.ToJson(Settings));
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3e0fff1aca044c40b9f5dc9d0bfaaa3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Audio/EnviroAudioModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8584d198954851d47a42ddc29a12e3ee
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,263 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a3e0fff1aca044c40b9f5dc9d0bfaaa3, type: 3}
|
||||
m_Name: Default Audio Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 1
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
Settings:
|
||||
ambientClips:
|
||||
- showEditor: 1
|
||||
name: Day
|
||||
audioClip: {fileID: 8300000, guid: 3e0b793299afd7c4086f6dfcd604aaba, type: 3}
|
||||
audioMixerGroup: {fileID: -7356562420348432203, guid: c5196b1e1a81a964ab0079efa98e857b, type: 2}
|
||||
playBackType: 1
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 1
|
||||
volume: 1
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: -0.000000659857
|
||||
outSlope: -0.000000659857
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.496813
|
||||
value: -0.00000032782555
|
||||
inSlope: 0.026825864
|
||||
outSlope: 0.026825864
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.12836285
|
||||
- serializedVersion: 3
|
||||
time: 0.5332272
|
||||
value: 0.69103265
|
||||
inSlope: 2.2555194
|
||||
outSlope: 2.2555194
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.0717938
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 1
|
||||
inSlope: 0.050087996
|
||||
outSlope: 0.050087996
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.15470096
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
- showEditor: 1
|
||||
name: Night
|
||||
audioClip: {fileID: 8300000, guid: eef01bfe93973f4419f0b3dd1b7a6a06, type: 3}
|
||||
audioMixerGroup: {fileID: -7356562420348432203, guid: c5196b1e1a81a964ab0079efa98e857b, type: 2}
|
||||
playBackType: 1
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 1
|
||||
volume: 1
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0.0058403015
|
||||
value: 0.003780365
|
||||
inSlope: 0.40376505
|
||||
outSlope: 0.40376505
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.30587992
|
||||
value: 0.12492588
|
||||
inSlope: 0.9373293
|
||||
outSlope: 0.9373293
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.45850945
|
||||
value: 0.39840025
|
||||
inSlope: -0.15356094
|
||||
outSlope: -0.15356094
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.3681847
|
||||
outWeight: 0.09808861
|
||||
- serializedVersion: 3
|
||||
time: 0.51107603
|
||||
value: 0.00567906
|
||||
inSlope: -0.03341259
|
||||
outSlope: -0.03341259
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.11550105
|
||||
- serializedVersion: 3
|
||||
time: 1.0029275
|
||||
value: 0.0013360546
|
||||
inSlope: -0.07205321
|
||||
outSlope: -0.07205321
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.15684973
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
weatherClips:
|
||||
- showEditor: 1
|
||||
name: Light Rain
|
||||
audioClip: {fileID: 8300000, guid: 84e5ea3df3fc44749b4bf8e1fe360d49, type: 3}
|
||||
audioMixerGroup: {fileID: 0}
|
||||
playBackType: 0
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 1
|
||||
volume: 0
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve: []
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
- showEditor: 1
|
||||
name: Medium Rain
|
||||
audioClip: {fileID: 8300000, guid: c2b83583de6cc7c4ca613942c6fe8a76, type: 3}
|
||||
audioMixerGroup: {fileID: 0}
|
||||
playBackType: 0
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 1
|
||||
volume: 0
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve: []
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
- showEditor: 1
|
||||
name: Heavy Rain
|
||||
audioClip: {fileID: 8300000, guid: 6ff8b8db3a3fd6e4cbfa0995856ebaca, type: 3}
|
||||
audioMixerGroup: {fileID: 0}
|
||||
playBackType: 0
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 1
|
||||
volume: 0
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve: []
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
thunderClips:
|
||||
- showEditor: 1
|
||||
name: Thunder 1
|
||||
audioClip: {fileID: 8300000, guid: 6ca3bddd35a48a745b4dcecc9f65a83f, type: 3}
|
||||
audioMixerGroup: {fileID: 0}
|
||||
playBackType: 0
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 0
|
||||
volume: 1
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve: []
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
- showEditor: 1
|
||||
name: Thunder 2
|
||||
audioClip: {fileID: 8300000, guid: dd76e0dd59e215946a75c7338c043951, type: 3}
|
||||
audioMixerGroup: {fileID: 0}
|
||||
playBackType: 0
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 0
|
||||
volume: 1
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve: []
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
- showEditor: 1
|
||||
name: Thunder 3
|
||||
audioClip: {fileID: 8300000, guid: ee17606ad258a3543a73a326bf5bc5da, type: 3}
|
||||
audioMixerGroup: {fileID: 0}
|
||||
playBackType: 0
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 0
|
||||
volume: 1
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve: []
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
- showEditor: 1
|
||||
name: Thunder 4
|
||||
audioClip: {fileID: 8300000, guid: eb8c1b0f82ffe784da2459bc295b4854, type: 3}
|
||||
audioMixerGroup: {fileID: 0}
|
||||
playBackType: 0
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 0
|
||||
volume: 1
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve: []
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
- showEditor: 1
|
||||
name: Thunder 5
|
||||
audioClip: {fileID: 8300000, guid: e410de94ef87c1b4998b2d4731a717bc, type: 3}
|
||||
audioMixerGroup: {fileID: 0}
|
||||
playBackType: 0
|
||||
myAudioSource: {fileID: 0}
|
||||
loop: 0
|
||||
volume: 1
|
||||
volumeCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve: []
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
maxVolume: 1
|
||||
ambientMasterVolume: 1
|
||||
weatherMasterVolume: 1
|
||||
thunderMasterVolume: 1
|
||||
preset: {fileID: 0}
|
||||
ambientVolumeModifier: 0
|
||||
weatherVolumeModifier: 0
|
||||
thunderVolumeModifier: 0
|
||||
showAmbientSetupControls: 0
|
||||
showWeatherSetupControls: 0
|
||||
showThunderSetupControls: 0
|
||||
showAudioControls: 0
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fac88c4f2c49e2d429d7269d163c9947
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Audio/Preset/Default
|
||||
Audio Preset.asset
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3267a7fcfd1151b4a8b65af01324115d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,137 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroAurora
|
||||
{
|
||||
public bool useAurora = true;
|
||||
[Header("Aurora Intensity")]
|
||||
[Range(0f,1f)]
|
||||
public float auroraIntensityModifier = 1f;
|
||||
public AnimationCurve auroraIntensity = new AnimationCurve(new Keyframe(0f, 1f), new Keyframe(0.5f, 0.1f), new Keyframe(1f, 0f));
|
||||
|
||||
//
|
||||
[Header("Aurora Color and Brightness")]
|
||||
public Color auroraColor = new Color(0.1f, 0.5f, 0.7f);
|
||||
public float auroraBrightness = 75f;
|
||||
public float auroraContrast = 10f;
|
||||
//
|
||||
[Header("Aurora Height and Scale")]
|
||||
public float auroraHeight = 20000f;
|
||||
[Range(0f, 0.025f)]
|
||||
public float auroraScale = 0.01f;
|
||||
//
|
||||
[Header("Aurora Performance")]
|
||||
[Range(8, 32)]
|
||||
public int auroraSteps = 20;
|
||||
//
|
||||
[Header("Aurora Modelling and Animation")]
|
||||
public Vector4 auroraLayer1Settings = new Vector4(0.1f, 0.1f, 0f, 0.5f);
|
||||
public Vector4 auroraLayer2Settings = new Vector4(5f, 5f, 0f, 0.5f);
|
||||
public Vector4 auroraColorshiftSettings = new Vector4(0.05f, 0.05f, 0f, 5f);
|
||||
[Range(0f, 0.1f)]
|
||||
public float auroraSpeed = 0.005f;
|
||||
[Header("Aurora Textures")]
|
||||
public Texture2D aurora_layer_1;
|
||||
public Texture2D aurora_layer_2;
|
||||
public Texture2D aurora_colorshift;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroAuroraModule : EnviroModule
|
||||
{
|
||||
public Enviro.EnviroAurora Settings;
|
||||
public EnviroAuroraModule preset;
|
||||
public bool showAuroraControls;
|
||||
|
||||
|
||||
// Update Method
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
|
||||
if(!active)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance.Sky != null)
|
||||
{
|
||||
UpdateAuroraShader();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAuroraShader ()
|
||||
{
|
||||
if(!Settings.useAurora)
|
||||
{
|
||||
Shader.SetGlobalFloat("_Aurora", 0f);
|
||||
return;
|
||||
}
|
||||
else
|
||||
Shader.SetGlobalFloat("_Aurora", 1f);
|
||||
|
||||
if (Settings.aurora_layer_1 != null)
|
||||
Shader.SetGlobalTexture("_Aurora_Layer_1", Settings.aurora_layer_1);
|
||||
|
||||
if (Settings.aurora_layer_2 != null)
|
||||
Shader.SetGlobalTexture("_Aurora_Layer_2", Settings.aurora_layer_2);
|
||||
|
||||
if (Settings.aurora_colorshift != null)
|
||||
Shader.SetGlobalTexture("_Aurora_Colorshift", Settings.aurora_colorshift);
|
||||
|
||||
Shader.SetGlobalFloat("_AuroraIntensity", Mathf.Clamp01(Settings.auroraIntensityModifier * Settings.auroraIntensity.Evaluate(EnviroManager.instance.solarTime)));
|
||||
Shader.SetGlobalFloat("_AuroraBrightness", Settings.auroraBrightness);
|
||||
Shader.SetGlobalFloat("_AuroraContrast", Settings.auroraContrast);
|
||||
Shader.SetGlobalColor("_AuroraColor", Settings.auroraColor);
|
||||
Shader.SetGlobalFloat("_AuroraHeight", Settings.auroraHeight);
|
||||
Shader.SetGlobalFloat("_AuroraScale", Settings.auroraScale);
|
||||
Shader.SetGlobalFloat("_AuroraSpeed", Settings.auroraSpeed);
|
||||
Shader.SetGlobalFloat("_AuroraSteps", Settings.auroraSteps);
|
||||
Shader.SetGlobalFloat("_AuroraSteps", Settings.auroraSteps);
|
||||
Shader.SetGlobalVector("_Aurora_Tiling_Layer1", Settings.auroraLayer1Settings);
|
||||
Shader.SetGlobalVector("_Aurora_Tiling_Layer2", Settings.auroraLayer2Settings);
|
||||
Shader.SetGlobalVector("_Aurora_Tiling_ColorShift", Settings.auroraColorshiftSettings);
|
||||
}
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
Settings = JsonUtility.FromJson<Enviro.EnviroAurora>(JsonUtility.ToJson(preset.Settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroAuroraModule t = ScriptableObject.CreateInstance<EnviroAuroraModule>();
|
||||
t.name = "Aurora Preset";
|
||||
t.Settings = JsonUtility.FromJson<Enviro.EnviroAurora>(JsonUtility.ToJson(Settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
public void SaveModuleValues (EnviroAuroraModule module)
|
||||
{
|
||||
module.Settings = JsonUtility.FromJson<Enviro.EnviroAurora>(JsonUtility.ToJson(Settings));
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6910768c241d1924f921a3f44198cfe1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Aurora/EnviroAuroraModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a1cba72929520b4887fd961043e8fe7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 6910768c241d1924f921a3f44198cfe1, type: 3}
|
||||
m_Name: Default Aurora Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 0
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
Settings:
|
||||
useAurora: 1
|
||||
auroraIntensityModifier: 1
|
||||
auroraIntensity:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
- serializedVersion: 3
|
||||
time: 0.5
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
auroraColor: {r: 0.1, g: 0.5, b: 0.7, a: 1}
|
||||
auroraBrightness: 75
|
||||
auroraContrast: 10
|
||||
auroraHeight: 20000
|
||||
auroraScale: 0.01
|
||||
auroraSteps: 24
|
||||
auroraLayer1Settings: {x: 0.1, y: 0.1, z: 0, w: 0.5}
|
||||
auroraLayer2Settings: {x: 5, y: 5, z: 0, w: 0.5}
|
||||
auroraColorshiftSettings: {x: 0.05, y: 0.05, z: 0, w: 5}
|
||||
auroraSpeed: 0.005
|
||||
aurora_layer_1: {fileID: 2800000, guid: 3316634c3fa8231429eb988934de236c, type: 3}
|
||||
aurora_layer_2: {fileID: 2800000, guid: 25bf6a8e18b4471499e961d75d1777c2, type: 3}
|
||||
aurora_colorshift: {fileID: 2800000, guid: f99b7b1866c1ab3489d848a4ef3dd81b, type: 3}
|
||||
preset: {fileID: 0}
|
||||
showAuroraControls: 0
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 278933d28004c6b40ace276968b45b9e
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Aurora/Preset/Default
|
||||
Aurora Preset.asset
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a66e1fc504e6aff45ba345c76949ab44
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroDefault
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroDefaultModule : EnviroModule
|
||||
{
|
||||
public Enviro.EnviroDefault settings;
|
||||
public EnviroDefaultModule preset;
|
||||
public bool showDefaultControls;
|
||||
|
||||
|
||||
// Update Method
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
settings = JsonUtility.FromJson<Enviro.EnviroDefault>(JsonUtility.ToJson(preset.settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroDefaultModule t = ScriptableObject.CreateInstance<EnviroDefaultModule>();
|
||||
t.name = "Default Preset";
|
||||
t.settings = JsonUtility.FromJson<Enviro.EnviroDefault>(JsonUtility.ToJson(settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
public void SaveModuleValues (EnviroDefaultModule module)
|
||||
{
|
||||
module.settings = JsonUtility.FromJson<Enviro.EnviroDefault>(JsonUtility.ToJson(settings));
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f09341d4288862d4c869629f4b229df9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Default/EnviroDefaultModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b8b3ff041c621c488b1ef5eba3b1b8f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,311 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroEffectTypes
|
||||
{
|
||||
#if ENVIRO_VFXGRAPH
|
||||
public UnityEngine.VFX.VisualEffect myVFXGraph;
|
||||
#endif
|
||||
public GameObject prefabVFXGraph;
|
||||
public Vector3 localPositionOffsetVFXGraph;
|
||||
public Vector3 localRotationOffsetVFXGraph;
|
||||
public float maxEmissionVFXGraph;
|
||||
|
||||
public ParticleSystem mySystem;
|
||||
public string name;
|
||||
public GameObject prefab;
|
||||
public Vector3 localPositionOffset;
|
||||
public Vector3 localRotationOffset;
|
||||
public float emissionRate = 0f;
|
||||
public float maxEmission;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroEffects
|
||||
{
|
||||
public enum EnviroEffectSystemType
|
||||
{
|
||||
ParticleSystem,
|
||||
VFXGraph,
|
||||
Both
|
||||
}
|
||||
|
||||
public EnviroEffectSystemType enviroEffectSystemType = EnviroEffectSystemType.VFXGraph;
|
||||
public List<EnviroEffectTypes> effectTypes = new List<EnviroEffectTypes>();
|
||||
[Range(0f,2f)]
|
||||
public float particeEmissionRateModifier = 1f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[ExecuteInEditMode]
|
||||
public class EnviroEffectsModule : EnviroModule
|
||||
{
|
||||
public Enviro.EnviroEffects Settings;
|
||||
public EnviroEffectsModule preset;
|
||||
|
||||
//Inspector
|
||||
public bool showSetupControls;
|
||||
public bool showEmissionControls;
|
||||
public override void Enable ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
Setup();
|
||||
}
|
||||
|
||||
public override void Disable ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
private void Setup()
|
||||
{
|
||||
if(!active)
|
||||
return;
|
||||
|
||||
CreateEffects();
|
||||
}
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
if(EnviroManager.instance.Objects.effects != null)
|
||||
DestroyImmediate(EnviroManager.instance.Objects.effects);
|
||||
}
|
||||
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
UpdateEffects();
|
||||
}
|
||||
|
||||
public void CreateEffects()
|
||||
{
|
||||
if(EnviroManager.instance.Objects.effects != null)
|
||||
{
|
||||
EnviroHelper.DestroyExtended(EnviroManager.instance.Objects.effects);
|
||||
EnviroManager.instance.Objects.effects = null;
|
||||
}
|
||||
|
||||
|
||||
if(EnviroManager.instance.Objects.effects == null)
|
||||
{
|
||||
EnviroManager.instance.Objects.effects = new GameObject();
|
||||
EnviroManager.instance.Objects.effects.hideFlags = HideFlags.DontSave;
|
||||
EnviroManager.instance.Objects.effects.name = "Effects";
|
||||
EnviroManager.instance.Objects.effects.transform.SetParent(EnviroManager.instance.transform);
|
||||
EnviroManager.instance.Objects.effects.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
for(int i = 0; i < Settings.effectTypes.Count; i++)
|
||||
{
|
||||
if(Settings.effectTypes[i].mySystem != null)
|
||||
{
|
||||
EnviroHelper.DestroyExtended(Settings.effectTypes[i].mySystem.gameObject);
|
||||
Settings.effectTypes[i].mySystem = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
GameObject sys;
|
||||
|
||||
if(Settings.effectTypes[i].prefab != null)
|
||||
{
|
||||
sys = Instantiate(Settings.effectTypes[i].prefab,Settings.effectTypes[i].localPositionOffset,Quaternion.identity);
|
||||
sys.transform.SetParent(EnviroManager.instance.Objects.effects.transform);
|
||||
sys.name = Settings.effectTypes[i].name + " Particle System";
|
||||
sys.transform.localPosition = Settings.effectTypes[i].localPositionOffset;
|
||||
sys.transform.localEulerAngles = Settings.effectTypes[i].localRotationOffset;
|
||||
Settings.effectTypes[i].mySystem = sys.GetComponent<ParticleSystem>();
|
||||
|
||||
if(Settings.effectTypes[i].emissionRate <= 0f)
|
||||
{
|
||||
Settings.effectTypes[i].mySystem.Clear();
|
||||
Settings.effectTypes[i].mySystem.Stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if ENVIRO_VFXGRAPH
|
||||
if(Settings.effectTypes[i].prefabVFXGraph != null)
|
||||
{
|
||||
sys = Instantiate(Settings.effectTypes[i].prefabVFXGraph,Settings.effectTypes[i].localPositionOffsetVFXGraph,Quaternion.identity);
|
||||
sys.transform.SetParent(EnviroManager.instance.Objects.effects.transform);
|
||||
sys.name = Settings.effectTypes[i].name + " VFX Graph";
|
||||
sys.transform.localPosition = Settings.effectTypes[i].localPositionOffsetVFXGraph;
|
||||
sys.transform.localEulerAngles = Settings.effectTypes[i].localRotationOffsetVFXGraph;
|
||||
Settings.effectTypes[i].myVFXGraph = sys.GetComponent<UnityEngine.VFX.VisualEffect>();
|
||||
|
||||
if(Settings.effectTypes[i].emissionRate <= 0f)
|
||||
Settings.effectTypes[i].myVFXGraph.Stop();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public float GetEmissionRate(ParticleSystem system)
|
||||
{
|
||||
return system.emission.rateOverTime.constantMax;
|
||||
}
|
||||
|
||||
public void SetEmissionRate(ParticleSystem sys, float emissionRate)
|
||||
{
|
||||
var emission = sys.emission;
|
||||
var rate = emission.rateOverTime;
|
||||
rate.constantMax = emissionRate;
|
||||
emission.rateOverTime = rate;
|
||||
}
|
||||
|
||||
#if ENVIRO_VFXGRAPH
|
||||
public float GetEmissionRate(UnityEngine.VFX.VisualEffect system)
|
||||
{
|
||||
return system.GetFloat("Emission Rate");
|
||||
}
|
||||
|
||||
|
||||
public void SetEmissionRate(UnityEngine.VFX.VisualEffect system, float emissionRate)
|
||||
{
|
||||
system.SetFloat("Emission Rate", emissionRate);
|
||||
|
||||
|
||||
if(EnviroManager.instance.Environment != null)
|
||||
{
|
||||
system.SetVector3("Wind",new UnityEngine.Vector3 (EnviroManager.instance.Environment.Settings.windDirectionX,0f,EnviroManager.instance.Environment.Settings.windDirectionY));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
private void UpdateEffects()
|
||||
{
|
||||
Shader.SetGlobalFloat("_EnviroLightIntensity", EnviroManager.instance.solarTime);
|
||||
|
||||
|
||||
for(int i = 0; i < Settings.effectTypes.Count; i++)
|
||||
{
|
||||
#if ENVIRO_VFXGRAPH
|
||||
if(Settings.enviroEffectSystemType == EnviroEffects.EnviroEffectSystemType.VFXGraph)
|
||||
{
|
||||
if(Settings.effectTypes[i].myVFXGraph != null)
|
||||
{
|
||||
float currentEmission = Settings.effectTypes[i].maxEmissionVFXGraph * Settings.effectTypes[i].emissionRate * Settings.particeEmissionRateModifier;
|
||||
|
||||
SetEmissionRate(Settings.effectTypes[i].myVFXGraph,currentEmission);
|
||||
|
||||
if(currentEmission > 0f && Settings.effectTypes[i].myVFXGraph.aliveParticleCount < 1)
|
||||
Settings.effectTypes[i].myVFXGraph.Play();
|
||||
}
|
||||
|
||||
if(Settings.effectTypes[i].mySystem != null)
|
||||
{
|
||||
SetEmissionRate(Settings.effectTypes[i].mySystem,0f);
|
||||
|
||||
if(Settings.effectTypes[i].mySystem.isPlaying)
|
||||
Settings.effectTypes[i].mySystem.Stop();
|
||||
}
|
||||
|
||||
}
|
||||
else if(Settings.enviroEffectSystemType == EnviroEffects.EnviroEffectSystemType.ParticleSystem)
|
||||
{
|
||||
|
||||
if(Settings.effectTypes[i].mySystem != null)
|
||||
{
|
||||
float currentEmission = Settings.effectTypes[i].maxEmission * Settings.effectTypes[i].emissionRate * Settings.particeEmissionRateModifier;
|
||||
|
||||
SetEmissionRate(Settings.effectTypes[i].mySystem,currentEmission);
|
||||
|
||||
if(currentEmission > 0f && !Settings.effectTypes[i].mySystem.isPlaying)
|
||||
Settings.effectTypes[i].mySystem.Play();
|
||||
}
|
||||
|
||||
if(Settings.effectTypes[i].myVFXGraph != null)
|
||||
{
|
||||
SetEmissionRate(Settings.effectTypes[i].myVFXGraph,0f);
|
||||
|
||||
if (Settings.effectTypes[i].myVFXGraph.aliveParticleCount > 0)
|
||||
Settings.effectTypes[i].myVFXGraph.Stop();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Settings.effectTypes[i].myVFXGraph != null)
|
||||
{
|
||||
float currentEmission = Settings.effectTypes[i].maxEmissionVFXGraph * Settings.effectTypes[i].emissionRate * Settings.particeEmissionRateModifier;
|
||||
|
||||
SetEmissionRate(Settings.effectTypes[i].myVFXGraph,currentEmission);
|
||||
|
||||
if(currentEmission > 0f && Settings.effectTypes[i].myVFXGraph.aliveParticleCount < 1)
|
||||
Settings.effectTypes[i].myVFXGraph.Play();
|
||||
}
|
||||
|
||||
if(Settings.effectTypes[i].mySystem != null)
|
||||
{
|
||||
float currentEmission = Settings.effectTypes[i].maxEmission * Settings.effectTypes[i].emissionRate * Settings.particeEmissionRateModifier;
|
||||
|
||||
SetEmissionRate(Settings.effectTypes[i].mySystem,currentEmission);
|
||||
|
||||
if(currentEmission > 0f && !Settings.effectTypes[i].mySystem.isPlaying)
|
||||
Settings.effectTypes[i].mySystem.Play();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
if(Settings.effectTypes[i].mySystem != null)
|
||||
{
|
||||
float currentEmission = Settings.effectTypes[i].maxEmission * Settings.effectTypes[i].emissionRate * Settings.particeEmissionRateModifier;
|
||||
|
||||
SetEmissionRate(Settings.effectTypes[i].mySystem,currentEmission);
|
||||
|
||||
if(currentEmission > 0f && !Settings.effectTypes[i].mySystem.isPlaying)
|
||||
Settings.effectTypes[i].mySystem.Play();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
Settings = JsonUtility.FromJson<Enviro.EnviroEffects>(JsonUtility.ToJson(preset.Settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroEffectsModule t = ScriptableObject.CreateInstance<EnviroEffectsModule>();
|
||||
t.name = "Effects Module";
|
||||
t.Settings = JsonUtility.FromJson<Enviro.EnviroEffects>(JsonUtility.ToJson(Settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SaveModuleValues (EnviroEffectsModule module)
|
||||
{
|
||||
module.Settings = JsonUtility.FromJson<Enviro.EnviroEffects>(JsonUtility.ToJson(Settings));
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7aa6806f1fff5b489f26777d053c723
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Effects/EnviroEffectsModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8efd41a7193b0dd49be02a75377fc379
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: e7aa6806f1fff5b489f26777d053c723, type: 3}
|
||||
m_Name: Default Effects Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 1
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
Settings:
|
||||
enviroEffectSystemType: 1
|
||||
effectTypes:
|
||||
- prefabVFXGraph: {fileID: 217644638508447475, guid: c4dc37a82cd6e96449263392be3a47b5, type: 3}
|
||||
localPositionOffsetVFXGraph: {x: 0, y: 25, z: 0}
|
||||
localRotationOffsetVFXGraph: {x: 0, y: 0, z: 0}
|
||||
maxEmissionVFXGraph: 75000
|
||||
mySystem: {fileID: 0}
|
||||
name: Rain
|
||||
prefab: {fileID: 6936246916098640434, guid: bf3881f9fe64de14597de578d2acee5d, type: 3}
|
||||
localPositionOffset: {x: 0, y: 25, z: 0}
|
||||
localRotationOffset: {x: -90, y: 0, z: 0}
|
||||
emissionRate: 0
|
||||
maxEmission: 2000
|
||||
- prefabVFXGraph: {fileID: 217644638508447475, guid: 208b9da0ef19ebe4c8589225a19a508f, type: 3}
|
||||
localPositionOffsetVFXGraph: {x: 0, y: 25, z: 0}
|
||||
localRotationOffsetVFXGraph: {x: 0, y: 0, z: 0}
|
||||
maxEmissionVFXGraph: 75000
|
||||
mySystem: {fileID: 0}
|
||||
name: Snow
|
||||
prefab: {fileID: 1000011163096958, guid: 6ec12b7d8fc5e704fbbbe1641e4a6c56, type: 3}
|
||||
localPositionOffset: {x: 0, y: 25, z: 0}
|
||||
localRotationOffset: {x: -90, y: 0, z: 0}
|
||||
emissionRate: 0
|
||||
maxEmission: 2500
|
||||
particeEmissionRateModifier: 1
|
||||
preset: {fileID: 0}
|
||||
showSetupControls: 0
|
||||
showEmissionControls: 0
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59a8076f06e540343b875f850ac3b6a4
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.2.0
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Effects/Preset/Default
|
||||
Effects Preset.asset
|
||||
uploadId: 721859
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class EnviroModule : ScriptableObject
|
||||
{
|
||||
public bool showModuleInspector = false;
|
||||
public bool showSaveLoad = false;
|
||||
public bool active = true;
|
||||
|
||||
public virtual void Enable()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Disable()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void UpdateModule ()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f18644bfe4a6622429e017df5dcda800
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/EnviroModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7856f0e01443004a979dc5383e6042b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,328 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class EnviroEnvironment
|
||||
{
|
||||
//Seasons
|
||||
public enum Seasons
|
||||
{
|
||||
Spring,
|
||||
Summer,
|
||||
Autumn,
|
||||
Winter
|
||||
}
|
||||
public Seasons season;
|
||||
public bool changeSeason = true;
|
||||
|
||||
[Tooltip("Start Day of Year for Spring")]
|
||||
[Range(0, 366)]
|
||||
public int springStart = 60;
|
||||
[Tooltip("End Day of Year for Spring")]
|
||||
[Range(0, 366)]
|
||||
public int springEnd = 92;
|
||||
[Tooltip("Start Day of Year for Summer")]
|
||||
[Range(0, 366)]
|
||||
public int summerStart = 93;
|
||||
[Tooltip("End Day of Year for Summer")]
|
||||
[Range(0, 366)]
|
||||
public int summerEnd = 185;
|
||||
[Tooltip("Start Day of Year for Autumn")]
|
||||
[Range(0, 366)]
|
||||
public int autumnStart = 186;
|
||||
[Tooltip("End Day of Year for Autumn")]
|
||||
[Range(0, 366)]
|
||||
public int autumnEnd = 276;
|
||||
[Tooltip("Start Day of Year for Winter")]
|
||||
[Range(0, 366)]
|
||||
public int winterStart = 277;
|
||||
[Tooltip("End Day of Year for Winter")]
|
||||
[Range(0, 366)]
|
||||
public int winterEnd = 59;
|
||||
|
||||
//Temperature
|
||||
[Tooltip("Base Temperature in Spring")]
|
||||
public AnimationCurve springBaseTemperature = new AnimationCurve();
|
||||
[Tooltip("Base Temperature in Summer")]
|
||||
public AnimationCurve summerBaseTemperature = new AnimationCurve();
|
||||
[Tooltip("Base Temperature in Autumn")]
|
||||
public AnimationCurve autumnBaseTemperature = new AnimationCurve();
|
||||
[Tooltip("Base Temperature in Winter")]
|
||||
public AnimationCurve winterBaseTemperature = new AnimationCurve();
|
||||
[Tooltip("Current temperature.")]
|
||||
[Range(-50f, 50f)]
|
||||
public float temperature = 0f;
|
||||
[Tooltip("Temperature mod used for different weather types.")]
|
||||
[Range(-50f, 50f)]
|
||||
public float temperatureWeatherMod = 0f;
|
||||
[Tooltip("Custom temperature mod for gameplay use.")]
|
||||
[Range(-50f, 50f)]
|
||||
public float temperatureCustomMod = 0f;
|
||||
|
||||
[Tooltip("Temperature changing speed.")]
|
||||
public float temperatureChangingSpeed = 1f;
|
||||
|
||||
//Weather State
|
||||
[Tooltip("Current wetness for third party shader or gameplay.")]
|
||||
[Range(0f, 1f)]
|
||||
public float wetness = 0f;
|
||||
[Tooltip("Target wetness for third party shader or gameplay.")]
|
||||
[Range(0f, 1f)]
|
||||
public float wetnessTarget = 0f;
|
||||
[Tooltip("Current snow for third party shader or gameplay.")]
|
||||
[Range(0f, 1f)]
|
||||
public float snow = 0f;
|
||||
[Tooltip("Target snow for third party shader or gameplay.")]
|
||||
[Range(0f, 1f)]
|
||||
public float snowTarget = 0f;
|
||||
|
||||
[Tooltip("Speed of wetness accumulation.")]
|
||||
public float wetnessAccumulationSpeed = 1f;
|
||||
[Tooltip("Speed of wetness dries.")]
|
||||
public float wetnessDrySpeed = 1f;
|
||||
|
||||
[Tooltip("Speed of snow buildup.")]
|
||||
public float snowAccumulationSpeed = 1f;
|
||||
[Tooltip("Speed of how fast snow melts.")]
|
||||
public float snowMeltSpeed = 1f;
|
||||
|
||||
[Tooltip("Temperature when snow starts to melt.")]
|
||||
[Range(-20f, 20f)]
|
||||
public float snowMeltingTresholdTemperature = 1f;
|
||||
|
||||
//Wind
|
||||
[Range(-1f,1f)]
|
||||
public float windDirectionX, windDirectionY;
|
||||
[Range(0f,1f)]
|
||||
public float windSpeed = 0.1f;
|
||||
[Range(0f,1f)]
|
||||
public float windTurbulence = 0.1f;
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroEnvironmentModule : EnviroModule
|
||||
{
|
||||
public Enviro.EnviroEnvironment Settings;
|
||||
public EnviroEnvironmentModule preset;
|
||||
public bool showSeasonControls,showTemperatureControls,showWeatherStateControls,showWindControls;
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
CreateWindZone ();
|
||||
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance.Objects.windZone != null)
|
||||
DestroyImmediate(EnviroManager.instance.Objects.windZone.gameObject);
|
||||
|
||||
}
|
||||
|
||||
private void CreateWindZone ()
|
||||
{
|
||||
if(EnviroManager.instance.Objects.windZone == null)
|
||||
{
|
||||
GameObject wZ = new GameObject();
|
||||
wZ.name = "Wind Zone";
|
||||
wZ.transform.SetParent(EnviroManager.instance.transform);
|
||||
wZ.transform.localPosition = Vector3.zero;
|
||||
EnviroManager.instance.Objects.windZone = wZ.AddComponent<WindZone>();
|
||||
}
|
||||
}
|
||||
|
||||
// Update Method
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
if(!active)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance.Time != null)
|
||||
{
|
||||
UpdateTemperature(EnviroManager.instance.Time.GetUniversalTimeOfDay() / 24f);
|
||||
UpdateSeason();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateTemperature(1f);
|
||||
}
|
||||
|
||||
UpdateWindZone();
|
||||
UpdateWeatherState();
|
||||
}
|
||||
|
||||
//Changes season based on day settings.
|
||||
public void UpdateSeason()
|
||||
{
|
||||
if(Settings.changeSeason)
|
||||
{
|
||||
|
||||
int currentDay = EnviroManager.instance.Time.Settings.date.DayOfYear;
|
||||
|
||||
if(EnviroManager.instance.Time.Settings.calenderType == EnviroTime.CalenderType.Custom)
|
||||
{
|
||||
currentDay = EnviroManager.instance.Time.days + (EnviroManager.instance.Time.months - 1) * EnviroManager.instance.Time.Settings.daysInMonth;
|
||||
}
|
||||
|
||||
|
||||
if (currentDay >= Settings.springStart && currentDay <= Settings.springEnd)
|
||||
{
|
||||
ChangeSeason(EnviroEnvironment.Seasons.Spring);
|
||||
}
|
||||
else if (currentDay >= Settings.summerStart && currentDay <= Settings.summerEnd)
|
||||
{
|
||||
ChangeSeason(EnviroEnvironment.Seasons.Summer);
|
||||
}
|
||||
else if (currentDay >= Settings.autumnStart && currentDay <= Settings.autumnEnd)
|
||||
{
|
||||
ChangeSeason(EnviroEnvironment.Seasons.Autumn);
|
||||
}
|
||||
else if (currentDay >= Settings.winterStart || currentDay <= Settings.winterEnd)
|
||||
{
|
||||
ChangeSeason(EnviroEnvironment.Seasons.Winter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Changes Season
|
||||
public void ChangeSeason(EnviroEnvironment.Seasons season)
|
||||
{
|
||||
if(Settings.season != season)
|
||||
{
|
||||
EnviroManager.instance.NotifySeasonChanged(season);
|
||||
Settings.season = season;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Sets temperature based on time of day.
|
||||
public void UpdateTemperature (float timeOfDay)
|
||||
{
|
||||
float temperature = 0f;
|
||||
|
||||
switch (Settings.season)
|
||||
{
|
||||
case EnviroEnvironment.Seasons.Spring:
|
||||
temperature = Settings.springBaseTemperature.Evaluate(timeOfDay);
|
||||
break;
|
||||
case EnviroEnvironment.Seasons.Summer:
|
||||
temperature = Settings.summerBaseTemperature.Evaluate(timeOfDay);
|
||||
break;
|
||||
case EnviroEnvironment.Seasons.Autumn:
|
||||
temperature = Settings.autumnBaseTemperature.Evaluate(timeOfDay);
|
||||
break;
|
||||
case EnviroEnvironment.Seasons.Winter:
|
||||
temperature = Settings.winterBaseTemperature.Evaluate(timeOfDay);
|
||||
break;
|
||||
}
|
||||
|
||||
//Apply temperature mods
|
||||
temperature += Settings.temperatureWeatherMod;
|
||||
temperature += Settings.temperatureCustomMod;
|
||||
|
||||
//Set temperature
|
||||
Settings.temperature = Mathf.Lerp(Settings.temperature, temperature, Time.deltaTime * Settings.temperatureChangingSpeed);
|
||||
}
|
||||
|
||||
public void UpdateWeatherState()
|
||||
{
|
||||
// Wetness
|
||||
if (Settings.wetness < Settings.wetnessTarget)
|
||||
{
|
||||
// Raining
|
||||
Settings.wetness = Mathf.Lerp(Settings.wetness, Settings.wetnessTarget, Settings.wetnessAccumulationSpeed * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{ // Drying
|
||||
Settings.wetness = Mathf.Lerp(Settings.wetness, Settings.wetnessTarget, Settings.wetnessDrySpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if(Settings.wetness < 0.0001f)
|
||||
Settings.wetness = 0f;
|
||||
|
||||
Settings.wetness = Mathf.Clamp(Settings.wetness, 0f, 1f);
|
||||
|
||||
//Snow
|
||||
if (Settings.snow < Settings.snowTarget)
|
||||
{
|
||||
//Snowing
|
||||
Settings.snow = Mathf.Lerp(Settings.snow, Settings.snowTarget, Settings.snowAccumulationSpeed * Time.deltaTime);
|
||||
}
|
||||
else if (Settings.temperature > Settings.snowMeltingTresholdTemperature)
|
||||
{
|
||||
//Melting
|
||||
Settings.snow = Mathf.Lerp(Settings.snow, Settings.snowTarget, Settings.snowMeltSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if(Settings.snow < 0.0001f)
|
||||
Settings.snow = 0f;
|
||||
|
||||
Settings.snow = Mathf.Clamp(Settings.snow, 0f, 1f);
|
||||
}
|
||||
|
||||
private void UpdateWindZone()
|
||||
{
|
||||
if(EnviroManager.instance.Objects.windZone != null)
|
||||
{
|
||||
EnviroManager.instance.Objects.windZone.windMain = Settings.windSpeed;
|
||||
EnviroManager.instance.Objects.windZone.windTurbulence = Settings.windTurbulence;
|
||||
|
||||
Vector3 windDirection = new Vector3(-Settings.windDirectionX,0f,-Settings.windDirectionY);
|
||||
EnviroManager.instance.Objects.windZone.transform.forward = windDirection;
|
||||
// EnviroManager.instance.Objects.windZone.transform.Rotate(new Vector3(Settings.windDirectionX,0f,Settings.windDirectionY),Space.World);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
Settings = JsonUtility.FromJson<Enviro.EnviroEnvironment>(JsonUtility.ToJson(preset.Settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroEnvironmentModule t = ScriptableObject.CreateInstance<EnviroEnvironmentModule>();
|
||||
t.name = "Environment Preset";
|
||||
t.Settings = JsonUtility.FromJson<Enviro.EnviroEnvironment>(JsonUtility.ToJson(Settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
public void SaveModuleValues (EnviroEnvironmentModule module)
|
||||
{
|
||||
module.Settings = JsonUtility.FromJson<Enviro.EnviroEnvironment>(JsonUtility.ToJson(Settings));
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0586c1500fad0074693dd4176a399883
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Environment/EnviroEnvironmentModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03ce2aa1f1b60694cb8a09c64db825f0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,182 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0586c1500fad0074693dd4176a399883, type: 3}
|
||||
m_Name: Default Environment Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 1
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
Settings:
|
||||
season: 1
|
||||
changeSeason: 1
|
||||
springStart: 60
|
||||
springEnd: 92
|
||||
summerStart: 93
|
||||
summerEnd: 185
|
||||
autumnStart: 186
|
||||
autumnEnd: 276
|
||||
winterStart: 277
|
||||
winterEnd: 59
|
||||
springBaseTemperature:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 5
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.49166667
|
||||
value: 10
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 5
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
summerBaseTemperature:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 15
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.49166667
|
||||
value: 25
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 15
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
autumnBaseTemperature:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 5
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.49166667
|
||||
value: 10
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 5
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
winterBaseTemperature:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.49166667
|
||||
value: 5
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
temperature: 22.565174
|
||||
temperatureWeatherMod: 0
|
||||
temperatureCustomMod: 0
|
||||
temperatureChangingSpeed: 0.1
|
||||
wetness: 0
|
||||
wetnessTarget: 0
|
||||
snow: 0
|
||||
snowTarget: 0
|
||||
wetnessAccumulationSpeed: 1
|
||||
wetnessDrySpeed: 1
|
||||
snowAccumulationSpeed: 1
|
||||
snowMeltSpeed: 1
|
||||
snowMeltingTresholdTemperature: 1
|
||||
windDirectionX: 0.009
|
||||
windDirectionY: 0.157
|
||||
windSpeed: 0.25
|
||||
windTurbulence: 0.25
|
||||
preset: {fileID: 0}
|
||||
showSeasonControls: 0
|
||||
showTemperatureControls: 0
|
||||
showWeatherStateControls: 0
|
||||
showWindControls: 0
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2a8d80258fd83a409a05aa912abca80
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Environment/Preset/Default
|
||||
Environment Preset.asset
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 115d2b99df2d51e4387aca37d5606718
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class EnviroEvents
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroActionEvent : UnityEngine.Events.UnityEvent
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EnviroActionEvent onHourPassedActions = new EnviroActionEvent();
|
||||
public EnviroActionEvent onDayPassedActions = new EnviroActionEvent();
|
||||
public EnviroActionEvent onYearPassedActions = new EnviroActionEvent();
|
||||
public EnviroActionEvent onWeatherChangedActions = new EnviroActionEvent();
|
||||
public EnviroActionEvent onSeasonChangedActions = new EnviroActionEvent();
|
||||
public EnviroActionEvent onNightActions = new EnviroActionEvent();
|
||||
public EnviroActionEvent onDayActions = new EnviroActionEvent();
|
||||
public EnviroActionEvent onZoneChangedActions = new EnviroActionEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c3520f8107654e4d82b9470b3eb462a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Events/EnviroEventModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82bf5f2331e8b474682b8480280663a7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,193 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroFlatClouds
|
||||
{
|
||||
// Cirrus
|
||||
public bool useCirrusClouds = true;
|
||||
public Texture2D cirrusCloudsTex;
|
||||
[Range(0f,1f)]
|
||||
public float cirrusCloudsAlpha;
|
||||
[Range(0f,2f)]
|
||||
public float cirrusCloudsColorPower;
|
||||
[Range(0f,1f)]
|
||||
public float cirrusCloudsCoverage;
|
||||
[GradientUsage(true)]
|
||||
public Gradient cirrusCloudsColor;
|
||||
[Range(0f,1f)]
|
||||
public float cirrusCloudsWindIntensity = 0.5f;
|
||||
|
||||
// Flat Clouds
|
||||
public bool useFlatClouds = true;
|
||||
public Texture2D flatCloudsBaseTex;
|
||||
public Texture2D flatCloudsDetailTex;
|
||||
|
||||
[GradientUsage(true)]
|
||||
public Gradient flatCloudsLightColor;
|
||||
[GradientUsage(true)]
|
||||
public Gradient flatCloudsAmbientColor;
|
||||
|
||||
[Range(0f,2f)]
|
||||
public float flatCloudsLightIntensity = 1.0f;
|
||||
[Range(0f,2f)]
|
||||
public float flatCloudsAmbientIntensity = 1.0f;
|
||||
[Range(0f,2f)]
|
||||
public float flatCloudsShadowIntensity = 0.6f;
|
||||
[Range(1,12)]
|
||||
public float flatCloudsShadowSteps = 8;
|
||||
[Range(0f,1f)]
|
||||
public float flatCloudsHGPhase = 0.6f;
|
||||
[Range(0f,2f)]
|
||||
public float flatCloudsCoverage = 1f;
|
||||
[Range(0f,2f)]
|
||||
public float flatCloudsDensity = 1f;
|
||||
public float flatCloudsAltitude = 10f;
|
||||
public bool flatCloudsTonemapping;
|
||||
public float flatCloudsBaseTiling = 4f;
|
||||
public float flatCloudsDetailTiling = 10f;
|
||||
[Range(0f,1f)]
|
||||
public float flatCloudsWindIntensity = 0.2f;
|
||||
[Range(0f,1f)]
|
||||
public float flatCloudsDetailWindIntensity = 0.5f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroFlatCloudsModule : EnviroModule
|
||||
{
|
||||
public Enviro.EnviroFlatClouds settings;
|
||||
public EnviroFlatCloudsModule preset;
|
||||
[HideInInspector]
|
||||
public bool showCirrusCloudsControls;
|
||||
[HideInInspector]
|
||||
public bool show2DCloudsControls;
|
||||
[HideInInspector]
|
||||
public Vector2 cloudFlatBaseAnim;
|
||||
[HideInInspector]
|
||||
public Vector2 cloudFlatDetailAnim;
|
||||
[HideInInspector]
|
||||
public Vector2 cirrusAnim;
|
||||
|
||||
// Update Method
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
if(!active)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
UpdateWind ();
|
||||
|
||||
if(settings.useCirrusClouds)
|
||||
{
|
||||
Shader.SetGlobalFloat("_CirrusClouds",1f);
|
||||
|
||||
if(settings.cirrusCloudsTex != null)
|
||||
Shader.SetGlobalTexture("_CirrusCloudMap",settings.cirrusCloudsTex);
|
||||
|
||||
Shader.SetGlobalFloat("_CirrusCloudAlpha",settings.cirrusCloudsAlpha);
|
||||
Shader.SetGlobalFloat("_CirrusCloudCoverage",settings.cirrusCloudsCoverage);
|
||||
Shader.SetGlobalFloat("_CirrusCloudColorPower",settings.cirrusCloudsColorPower);
|
||||
Shader.SetGlobalColor("_CirrusCloudColor",settings.cirrusCloudsColor.Evaluate(EnviroManager.instance.solarTime));
|
||||
Shader.SetGlobalVector("_CirrusCloudAnimation", new Vector4(cirrusAnim.x, cirrusAnim.y, 0f, 0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
Shader.SetGlobalFloat("_CirrusClouds",0f);
|
||||
}
|
||||
|
||||
if(settings.useFlatClouds)
|
||||
{
|
||||
Shader.SetGlobalFloat("_FlatClouds",1f);
|
||||
|
||||
if(settings.flatCloudsBaseTex != null)
|
||||
Shader.SetGlobalTexture("_FlatCloudsBaseTexture",settings.flatCloudsBaseTex);
|
||||
|
||||
if(settings.flatCloudsDetailTex != null)
|
||||
Shader.SetGlobalTexture("_FlatCloudsDetailTexture",settings.flatCloudsDetailTex);
|
||||
|
||||
//_FlatCloudsAnimation;
|
||||
Shader.SetGlobalColor("_FlatCloudsLightColor", settings.flatCloudsLightColor.Evaluate(EnviroManager.instance.solarTime));
|
||||
Shader.SetGlobalColor("_FlatCloudsAmbientColor", settings.flatCloudsAmbientColor.Evaluate(EnviroManager.instance.solarTime));
|
||||
|
||||
Vector3 lightDirection = Vector3.forward;
|
||||
if(EnviroManager.instance.Objects.directionalLight != null)
|
||||
lightDirection = EnviroManager.instance.Objects.directionalLight.transform.forward;
|
||||
|
||||
Shader.SetGlobalVector("_FlatCloudsLightDirection",lightDirection);
|
||||
Shader.SetGlobalVector("_FlatCloudsLightingParams",new Vector4(settings.flatCloudsLightIntensity * 10f, settings.flatCloudsAmbientIntensity, settings.flatCloudsShadowIntensity,settings.flatCloudsHGPhase));
|
||||
Shader.SetGlobalVector("_FlatCloudsParams",new Vector4(settings.flatCloudsCoverage, settings.flatCloudsDensity * 5f, settings.flatCloudsAltitude,settings.flatCloudsShadowSteps));
|
||||
Shader.SetGlobalVector("_FlatCloudsTiling",new Vector4(settings.flatCloudsBaseTiling, settings.flatCloudsDetailTiling, 0f,0f));
|
||||
Shader.SetGlobalVector("_FlatCloudsAnimation", new Vector4(cloudFlatBaseAnim.x, cloudFlatBaseAnim.y, cloudFlatDetailAnim.x, cloudFlatDetailAnim.y));
|
||||
}
|
||||
else
|
||||
{
|
||||
Shader.SetGlobalFloat("_FlatClouds",0f);
|
||||
}
|
||||
}
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
settings = JsonUtility.FromJson<Enviro.EnviroFlatClouds>(JsonUtility.ToJson(preset.settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateWind ()
|
||||
{
|
||||
|
||||
|
||||
if(EnviroManager.instance.Environment != null)
|
||||
{
|
||||
cloudFlatBaseAnim += new Vector2(((EnviroManager.instance.Environment.Settings.windSpeed * EnviroManager.instance.Environment.Settings.windDirectionX) * settings.flatCloudsWindIntensity) * Time.deltaTime * 0.01f, ((EnviroManager.instance.Environment.Settings.windSpeed * EnviroManager.instance.Environment.Settings.windDirectionY) * settings.flatCloudsWindIntensity) * Time.deltaTime * 0.01f);
|
||||
cloudFlatDetailAnim += new Vector2(((EnviroManager.instance.Environment.Settings.windSpeed * EnviroManager.instance.Environment.Settings.windDirectionX) * settings.flatCloudsDetailWindIntensity) * Time.deltaTime * 0.1f, ((EnviroManager.instance.Environment.Settings.windSpeed * EnviroManager.instance.Environment.Settings.windDirectionY) * settings.flatCloudsDetailWindIntensity) * Time.deltaTime * 0.1f);
|
||||
cirrusAnim += new Vector2(((EnviroManager.instance.Environment.Settings.windSpeed * EnviroManager.instance.Environment.Settings.windDirectionX) * settings.cirrusCloudsWindIntensity) * Time.deltaTime * 0.01f, ((EnviroManager.instance.Environment.Settings.windSpeed * EnviroManager.instance.Environment.Settings.windDirectionY) * settings.cirrusCloudsWindIntensity) * Time.deltaTime * 0.01f);
|
||||
}
|
||||
else
|
||||
{
|
||||
cloudFlatBaseAnim += new Vector2(settings.flatCloudsWindIntensity * Time.deltaTime * 0.01f,settings.flatCloudsWindIntensity * Time.deltaTime * 0.01f);
|
||||
cloudFlatDetailAnim += new Vector2(settings.flatCloudsDetailWindIntensity * Time.deltaTime * 0.1f,settings.flatCloudsDetailWindIntensity * Time.deltaTime * 0.1f);
|
||||
cirrusAnim += new Vector2(settings.cirrusCloudsWindIntensity * Time.deltaTime * 0.01f,settings.cirrusCloudsWindIntensity * Time.deltaTime * 0.01f);
|
||||
}
|
||||
|
||||
cirrusAnim = EnviroHelper.PingPong(cirrusAnim);
|
||||
cloudFlatBaseAnim = EnviroHelper.PingPong(cloudFlatBaseAnim);
|
||||
cloudFlatDetailAnim = EnviroHelper.PingPong(cloudFlatDetailAnim);
|
||||
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroFlatCloudsModule t = ScriptableObject.CreateInstance<EnviroFlatCloudsModule>();
|
||||
t.name = "Flat Clouds Preset";
|
||||
t.settings = JsonUtility.FromJson<Enviro.EnviroFlatClouds>(JsonUtility.ToJson(settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
public void SaveModuleValues (EnviroFlatCloudsModule module)
|
||||
{
|
||||
module.settings = JsonUtility.FromJson<Enviro.EnviroFlatClouds>(JsonUtility.ToJson(settings));
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b982c9fba9faf3a43bf4a9e7ced867d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/FlatClouds/EnviroFlatCloudsModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a6a4b2e84e90ba4fb3010a5c31d5a9f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,133 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b982c9fba9faf3a43bf4a9e7ced867d7, type: 3}
|
||||
m_Name: Default Flat Clouds Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 0
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
settings:
|
||||
useCirrusClouds: 1
|
||||
cirrusCloudsTex: {fileID: 2800000, guid: 75c66597a85001644b2de40147b8d196, type: 3}
|
||||
cirrusCloudsAlpha: 0.5
|
||||
cirrusCloudsColorPower: 1
|
||||
cirrusCloudsCoverage: 0.5
|
||||
cirrusCloudsColor:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0, g: 0, b: 0, a: 1}
|
||||
key1: {r: 0, g: 0, b: 0, a: 1}
|
||||
key2: {r: 1, g: 0.18127085, b: 0, a: 0.9843137}
|
||||
key3: {r: 0.91764706, g: 0.78431374, b: 0.6431373, a: 0.9843137}
|
||||
key4: {r: 0.91764706, g: 0.8627451, b: 0.80784315, a: 0.9843137}
|
||||
key5: {r: 0.4627451, g: 0.9843137, b: 0.83137256, a: 0.9843137}
|
||||
key6: {r: 0.4627451, g: 0.9843137, b: 0.83137256, a: 0.9843137}
|
||||
key7: {r: 0.4627451, g: 0.9843137, b: 0.83137256, a: 0.9843137}
|
||||
ctime0: 0
|
||||
ctime1: 29696
|
||||
ctime2: 31641
|
||||
ctime3: 36700
|
||||
ctime4: 65535
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 5
|
||||
m_NumAlphaKeys: 2
|
||||
cirrusCloudsWindIntensity: 0.5
|
||||
useFlatClouds: 0
|
||||
flatCloudsBaseTex: {fileID: 2800000, guid: d178a8cc601a00f48914c0bfd42c77d5, type: 3}
|
||||
flatCloudsDetailTex: {fileID: 2800000, guid: 2e0e351a1a0d49545a3dd0264e7ac2d9, type: 3}
|
||||
flatCloudsLightColor:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0, g: 0, b: 0, a: 1}
|
||||
key1: {r: 0.12615699, g: 0.13726778, b: 0.1981132, a: 1}
|
||||
key2: {r: 1, g: 0.18127085, b: 0, a: 0}
|
||||
key3: {r: 0.91764706, g: 0.78431374, b: 0.6431373, a: 0}
|
||||
key4: {r: 0.91764706, g: 0.8627451, b: 0.80784315, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 29696
|
||||
ctime2: 31641
|
||||
ctime3: 36700
|
||||
ctime4: 65535
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 5
|
||||
m_NumAlphaKeys: 2
|
||||
flatCloudsAmbientColor:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0, g: 0, b: 0, a: 1}
|
||||
key1: {r: 0.06781771, g: 0.07401677, b: 0.11320752, a: 1}
|
||||
key2: {r: 0.17319329, g: 0.2085657, b: 0.26415092, a: 0}
|
||||
key3: {r: 0.23535956, g: 0.28180525, b: 0.4056604, a: 0}
|
||||
key4: {r: 0, g: 0, b: 0, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 29491
|
||||
ctime2: 33539
|
||||
ctime3: 65535
|
||||
ctime4: 0
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 4
|
||||
m_NumAlphaKeys: 2
|
||||
flatCloudsLightIntensity: 0.478
|
||||
flatCloudsAmbientIntensity: 0.969
|
||||
flatCloudsShadowIntensity: 0.6
|
||||
flatCloudsShadowSteps: 8
|
||||
flatCloudsHGPhase: 0.8
|
||||
flatCloudsCoverage: 1.189
|
||||
flatCloudsDensity: 1
|
||||
flatCloudsAltitude: 1
|
||||
flatCloudsTonemapping: 0
|
||||
flatCloudsBaseTiling: 1
|
||||
flatCloudsDetailTiling: 10
|
||||
flatCloudsWindIntensity: 1
|
||||
flatCloudsDetailWindIntensity: 0.5
|
||||
preset: {fileID: 0}
|
||||
showCirrusCloudsControls: 0
|
||||
show2DCloudsControls: 0
|
||||
cloudFlatBaseAnim: {x: 0, y: 0}
|
||||
cloudFlatDetailAnim: {x: 0, y: 0}
|
||||
cirrusAnim: {x: 0, y: 0}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fcdd472bd6a8ec429fc1e9bc978c4fa
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/FlatClouds/Preset/Default
|
||||
Flat Clouds Preset.asset
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d15c93c666974ac4b83898ac5746c0d5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4eacb969ef7bfec4ba69d66b0a873f2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Fog/EnviroFogModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,116 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
namespace Enviro
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Enviro 3/Volumetric Light")]
|
||||
public class EnviroVolumetricFogLight : MonoBehaviour
|
||||
{
|
||||
[Range(0f,2f)]
|
||||
public float intensity = 1.0f;
|
||||
[Range(0f,2f)]
|
||||
public float range = 1.0f;
|
||||
|
||||
private Light myLight;
|
||||
|
||||
private bool initialized = false;
|
||||
private CommandBuffer cascadeShadowCB;
|
||||
//private CommandBuffer shadowMatrixBuffer;
|
||||
|
||||
|
||||
|
||||
public bool isOn
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!isActiveAndEnabled)
|
||||
return false;
|
||||
|
||||
Init();
|
||||
|
||||
return myLight.enabled;
|
||||
}
|
||||
|
||||
private set{}
|
||||
}
|
||||
|
||||
new public Light light {get{Init(); return myLight;} private set{}}
|
||||
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
Init();
|
||||
if(EnviroManager.instance != null && EnviroManager.instance.Fog != null)
|
||||
AddToLightManager();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
#if !ENVIRO_URP && !ENVIRO_HDRP
|
||||
if(cascadeShadowCB != null && myLight != null && myLight.type == LightType.Directional)
|
||||
myLight.RemoveCommandBuffer(LightEvent.AfterShadowMap, cascadeShadowCB);
|
||||
#endif
|
||||
// if(shadowMatrixBuffer != null && myLight != null && myLight.type == LightType.Directional)
|
||||
// myLight.RemoveCommandBuffer(LightEvent.BeforeScreenspaceMask, shadowMatrixBuffer);
|
||||
|
||||
if(EnviroManager.instance != null && EnviroManager.instance.Fog != null)
|
||||
RemoveFromLightManager();
|
||||
}
|
||||
|
||||
void AddToLightManager()
|
||||
{
|
||||
bool addedToMgr = false;
|
||||
|
||||
for(int i = 0; i < EnviroManager.instance.Fog.fogLights.Count; i++)
|
||||
{
|
||||
if(EnviroManager.instance.Fog.fogLights[i] == this)
|
||||
{
|
||||
addedToMgr = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!addedToMgr)
|
||||
EnviroManager.instance.Fog.AddLight(this);
|
||||
}
|
||||
|
||||
void RemoveFromLightManager()
|
||||
{
|
||||
for(int i = 0; i < EnviroManager.instance.Fog.fogLights.Count; i++)
|
||||
{
|
||||
if(EnviroManager.instance.Fog.fogLights[i] == this)
|
||||
{
|
||||
EnviroManager.instance.Fog.RemoveLight(this);
|
||||
initialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Init()
|
||||
{
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
myLight = GetComponent<Light>();
|
||||
|
||||
#if !ENVIRO_URP && !ENVIRO_HDRP
|
||||
if(myLight.type == LightType.Directional)
|
||||
{
|
||||
cascadeShadowCB = new CommandBuffer();
|
||||
cascadeShadowCB.name = "Dir Light Command Buffer";
|
||||
cascadeShadowCB.SetGlobalTexture("_CascadeShadowMapTexture", new UnityEngine.Rendering.RenderTargetIdentifier(UnityEngine.Rendering.BuiltinRenderTextureType.CurrentActive));
|
||||
myLight.AddCommandBuffer(LightEvent.AfterShadowMap, cascadeShadowCB);
|
||||
|
||||
//shadowMatrixBuffer = new CommandBuffer();
|
||||
//shadowMatrixBuffer.name = "Extract Shadow Matrix Buffer";
|
||||
//myLight.AddCommandBuffer(LightEvent.BeforeShadowMap, shadowMatrixBuffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84329a1a5ad77384a9c3bb7ed65d8506
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Fog/EnviroVolumetricFogLight.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61db9d7312f446347a562504188fc2c9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,162 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4eacb969ef7bfec4ba69d66b0a873f2f, type: 3}
|
||||
m_Name: Default Fog Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 1
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
Settings:
|
||||
volumetrics: 1
|
||||
steps: 32
|
||||
quality: 1
|
||||
scattering: 0.425
|
||||
scatteringMultiplier:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 8
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
- serializedVersion: 3
|
||||
time: 0.29862836
|
||||
value: 7.1266994
|
||||
inSlope: -7.9367094
|
||||
outSlope: -7.9367094
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.1494251
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.41374835
|
||||
value: 1.9498584
|
||||
inSlope: -5.9926996
|
||||
outSlope: -5.9926996
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.515421
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
extinction: 0.029
|
||||
anistropy: 0.5
|
||||
maxRange: 1000
|
||||
maxRangePointSpot: 100
|
||||
noiseIntensity: 0
|
||||
noiseScale: 0
|
||||
windDirection: {x: 3.9, y: 0, z: 0}
|
||||
noise: {fileID: 0}
|
||||
ditheringTex: {fileID: 2800000, guid: 711e788cbc742bb439b3c7cad60651e3, type: 3}
|
||||
fog: 1
|
||||
fogQualityMode: 0
|
||||
floatingPointOriginMod: {x: 0, y: 0, z: 0}
|
||||
globalFogHeight: 0
|
||||
fogDensity: 0.097
|
||||
fogHeightFalloff: 0.0045
|
||||
fogHeight: 0
|
||||
fogDensity2: 0.073
|
||||
fogHeightFalloff2: 0.05
|
||||
fogHeight2: -25
|
||||
fogMaxOpacity: 1
|
||||
startDistance: 0.01
|
||||
fogColorBlend: 0.7
|
||||
fogColorMod: {r: 1, g: 1, b: 1, a: 1}
|
||||
blockScattering: 1
|
||||
ambientColorGradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0.23549305, g: 0.2427107, b: 0.7924528, a: 1}
|
||||
key1: {r: 0.16073336, g: 0.22812635, b: 0.7924528, a: 1}
|
||||
key2: {r: 0.35590956, g: 0.44551674, b: 0.5849056, a: 0}
|
||||
key3: {r: 2.5796902, g: 2.651018, b: 2.8293376, a: 0}
|
||||
key4: {r: 2.5796902, g: 2.651018, b: 2.8293376, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 29491
|
||||
ctime2: 33539
|
||||
ctime3: 65535
|
||||
ctime4: 65535
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 4
|
||||
m_NumAlphaKeys: 2
|
||||
unityFog: 0
|
||||
unityFogMode: 2
|
||||
unityFogDensity: 0.05
|
||||
unityFogStartDistance: 0
|
||||
unityFogEndDistance: 1000
|
||||
unityFogColor:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0, g: 0, b: 0, a: 1}
|
||||
key1: {r: 0.0146404365, g: 0.019780159, b: 0.066037714, a: 1}
|
||||
key2: {r: 0.12589, g: 0.15198022, b: 0.38679248, a: 0}
|
||||
key3: {r: 0.6415094, g: 0.39747813, b: 0.26326096, a: 0}
|
||||
key4: {r: 0.53266287, g: 0.63567483, b: 0.8490566, a: 0}
|
||||
key5: {r: 0.82702917, g: 0.8807278, b: 0.990566, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 9830
|
||||
ctime2: 23130
|
||||
ctime3: 32768
|
||||
ctime4: 36430
|
||||
ctime5: 65535
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 6
|
||||
m_NumAlphaKeys: 2
|
||||
preset: {fileID: 0}
|
||||
showFogControls: 0
|
||||
showVolumetricsControls: 0
|
||||
showUnityFogControls: 0
|
||||
fogLights: []
|
||||
customFogDensityModifer: 1
|
||||
fogMat: {fileID: 0}
|
||||
volumetricsMat: {fileID: 0}
|
||||
blurMat: {fileID: 0}
|
||||
blurMat2: {fileID: 0}
|
||||
volumetricsRenderTexture: {fileID: 0}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6625884995235d049bd7f2f1de182577
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Fog/Preset/Default
|
||||
Fog Preset.asset
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a7145ce8216a5e4d96edca8030aa4c9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,509 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroLighting
|
||||
{
|
||||
// DirectLighting
|
||||
public enum LightingMode
|
||||
{
|
||||
Single,
|
||||
Dual
|
||||
};
|
||||
|
||||
public LightingMode lightingMode;
|
||||
public bool setDirectLighting = true;
|
||||
public int updateIntervallFrames = 2;
|
||||
public AnimationCurve sunIntensityCurve;
|
||||
public AnimationCurve moonIntensityCurve;
|
||||
[GradientUsageAttribute(true)]
|
||||
public Gradient sunColorGradient;
|
||||
[GradientUsageAttribute(true)]
|
||||
public Gradient moonColorGradient;
|
||||
public AnimationCurve sunIntensityCurveHDRP = new AnimationCurve();
|
||||
public AnimationCurve moonIntensityCurveHDRP = new AnimationCurve();
|
||||
public AnimationCurve lightColorTemperatureHDRP = new AnimationCurve();
|
||||
[GradientUsageAttribute(true)]
|
||||
public Gradient ambientColorTintHDRP;
|
||||
public float lightIntensityHDRP = 750f;
|
||||
public bool controlExposure = true;
|
||||
public AnimationCurve sceneExposure = new AnimationCurve();
|
||||
public bool controlIndirectLighting = true;
|
||||
public AnimationCurve diffuseIndirectIntensity = new AnimationCurve();
|
||||
public AnimationCurve reflectionIndirectIntensity = new AnimationCurve();
|
||||
|
||||
[Range(0f,2f)]
|
||||
public float directLightIntensityModifier = 1f;
|
||||
|
||||
//Ambient Lighting
|
||||
public bool setAmbientLighting = true;
|
||||
public UnityEngine.Rendering.AmbientMode ambientMode;
|
||||
[GradientUsage(true)]
|
||||
public Gradient ambientSkyColorGradient;
|
||||
[GradientUsage(true)]
|
||||
public Gradient ambientEquatorColorGradient;
|
||||
[GradientUsage(true)]
|
||||
public Gradient ambientGroundColorGradient;
|
||||
public AnimationCurve ambientIntensityCurve;
|
||||
|
||||
[Range(0f,2f)]
|
||||
public float ambientIntensityModifier = 1f;
|
||||
|
||||
public bool ambientUpdateEveryFrame = false;
|
||||
|
||||
[Range(0f,2f)]
|
||||
public float ambientUpdateIntervall = 0.1f;
|
||||
|
||||
[Range(0f,1f)]
|
||||
public float shadowIntensity = 1f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[ExecuteInEditMode]
|
||||
public class EnviroLightingModule : EnviroModule
|
||||
{
|
||||
public Enviro.EnviroLighting Settings;
|
||||
public EnviroLightingModule preset;
|
||||
|
||||
private int currentFrame;
|
||||
private float lastAmbientSkyboxUpdate;
|
||||
|
||||
//Inspector
|
||||
public bool showDirectLightingControls;
|
||||
public bool showAmbientLightingControls;
|
||||
public bool showReflectionControls;
|
||||
|
||||
#if ENVIRO_HDRP
|
||||
public UnityEngine.Rendering.HighDefinition.HDAdditionalLightData directionalLightHDRP;
|
||||
public UnityEngine.Rendering.HighDefinition.HDAdditionalLightData additionalLightHDRP;
|
||||
public UnityEngine.Rendering.HighDefinition.Exposure exposureHDRP;
|
||||
public UnityEngine.Rendering.HighDefinition.IndirectLightingController indirectLightingHDRP;
|
||||
#endif
|
||||
|
||||
public override void Enable ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
Setup();
|
||||
}
|
||||
|
||||
public override void Disable ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
//Applies changes when you switch the lighting mode.
|
||||
public void ApplyLightingChanges ()
|
||||
{
|
||||
Cleanup();
|
||||
Setup();
|
||||
}
|
||||
|
||||
private void Setup()
|
||||
{
|
||||
if(EnviroManager.instance.Objects.directionalLight == null)
|
||||
{
|
||||
GameObject newLight = new GameObject();
|
||||
|
||||
if(Settings.lightingMode == EnviroLighting.LightingMode.Single)
|
||||
newLight.name = "Sun and Moon Directional Light";
|
||||
else
|
||||
newLight.name = "Sun Directional Light";
|
||||
|
||||
newLight.transform.SetParent(EnviroManager.instance.transform);
|
||||
newLight.transform.localPosition = Vector3.zero;
|
||||
EnviroManager.instance.Objects.directionalLight = newLight.AddComponent<Light>();
|
||||
EnviroManager.instance.Objects.directionalLight.type = LightType.Directional;
|
||||
EnviroManager.instance.Objects.directionalLight.shadows = LightShadows.Soft;
|
||||
}
|
||||
|
||||
if(EnviroManager.instance.Objects.additionalDirectionalLight == null && Settings.lightingMode == EnviroLighting.LightingMode.Dual)
|
||||
{
|
||||
GameObject newLight = new GameObject();
|
||||
newLight.name = "Moon Directional Light";
|
||||
newLight.transform.SetParent(EnviroManager.instance.transform);
|
||||
newLight.transform.localPosition = Vector3.zero;
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight = newLight.AddComponent<Light>();
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.type = LightType.Directional;
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.shadows = LightShadows.Soft;
|
||||
}
|
||||
else if (EnviroManager.instance.Objects.additionalDirectionalLight != null && Settings.lightingMode == EnviroLighting.LightingMode.Single)
|
||||
{
|
||||
DestroyImmediate(EnviroManager.instance.Objects.additionalDirectionalLight.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance.Objects.directionalLight != null)
|
||||
DestroyImmediate(EnviroManager.instance.Objects.directionalLight.gameObject);
|
||||
|
||||
if(EnviroManager.instance.Objects.additionalDirectionalLight != null)
|
||||
DestroyImmediate(EnviroManager.instance.Objects.additionalDirectionalLight.gameObject);
|
||||
}
|
||||
|
||||
// Update Method
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
if(!active)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
currentFrame++;
|
||||
|
||||
if(currentFrame >= Settings.updateIntervallFrames)
|
||||
{
|
||||
EnviroManager.instance.updateSkyAndLighting = true;
|
||||
currentFrame = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.updateSkyAndLighting = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Update Direct Lighting
|
||||
if(EnviroManager.instance.Objects.directionalLight != null && Settings.setDirectLighting)
|
||||
{
|
||||
#if !ENVIRO_HDRP
|
||||
if(EnviroManager.instance.updateSkyAndLighting)
|
||||
UpdateDirectLighting ();
|
||||
#else
|
||||
if(EnviroManager.instance.updateSkyAndLighting)
|
||||
UpdateDirectLightingHDRP();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (Settings.setAmbientLighting)
|
||||
{
|
||||
#if !ENVIRO_HDRP
|
||||
UpdateAmbientLighting (Settings.ambientUpdateEveryFrame);
|
||||
#else
|
||||
if(EnviroManager.instance.updateSkyAndLighting)
|
||||
UpdateAmbientLightingHDRP ();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ENVIRO_HDRP
|
||||
if(EnviroManager.instance.updateSkyAndLighting)
|
||||
UpdateExposureHDRP ();
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void UpdateDirectLighting ()
|
||||
{
|
||||
if(Settings.lightingMode == EnviroLighting.LightingMode.Single)
|
||||
{
|
||||
if(!EnviroManager.instance.isNight)
|
||||
{
|
||||
//Set light to sun
|
||||
EnviroManager.instance.Objects.directionalLight.transform.rotation = EnviroManager.instance.Objects.sun.transform.rotation;
|
||||
EnviroManager.instance.Objects.directionalLight.intensity = Settings.sunIntensityCurve.Evaluate(EnviroManager.instance.solarTime) * Settings.directLightIntensityModifier;
|
||||
EnviroManager.instance.Objects.directionalLight.color = Settings.sunColorGradient.Evaluate(EnviroManager.instance.solarTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Set light to moon
|
||||
EnviroManager.instance.Objects.directionalLight.transform.rotation = EnviroManager.instance.Objects.moon.transform.rotation;
|
||||
EnviroManager.instance.Objects.directionalLight.intensity = Settings.moonIntensityCurve.Evaluate(EnviroManager.instance.lunarTime) * Settings.directLightIntensityModifier;
|
||||
EnviroManager.instance.Objects.directionalLight.color = Settings.moonColorGradient.Evaluate(EnviroManager.instance.lunarTime);
|
||||
}
|
||||
|
||||
EnviroManager.instance.Objects.directionalLight.shadowStrength = Settings.shadowIntensity;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Sun
|
||||
EnviroManager.instance.Objects.directionalLight.transform.rotation = EnviroManager.instance.Objects.sun.transform.rotation;
|
||||
EnviroManager.instance.Objects.directionalLight.intensity = Settings.sunIntensityCurve.Evaluate(EnviroManager.instance.solarTime) * Settings.directLightIntensityModifier;
|
||||
EnviroManager.instance.Objects.directionalLight.color = Settings.sunColorGradient.Evaluate(EnviroManager.instance.solarTime);
|
||||
EnviroManager.instance.Objects.directionalLight.shadowStrength = Settings.shadowIntensity;
|
||||
//Moon
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.transform.rotation = EnviroManager.instance.Objects.moon.transform.rotation;
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.intensity = Settings.moonIntensityCurve.Evaluate(EnviroManager.instance.lunarTime) * Settings.directLightIntensityModifier;
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.color = Settings.moonColorGradient.Evaluate(EnviroManager.instance.lunarTime);
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.shadowStrength = Settings.shadowIntensity;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if ENVIRO_HDRP
|
||||
public void UpdateDirectLightingHDRP ()
|
||||
{
|
||||
if(directionalLightHDRP == null && EnviroManager.instance.Objects.directionalLight != null)
|
||||
directionalLightHDRP = EnviroManager.instance.Objects.directionalLight.gameObject.GetComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalLightData>();
|
||||
|
||||
if(additionalLightHDRP == null && EnviroManager.instance.Objects.additionalDirectionalLight != null)
|
||||
additionalLightHDRP = EnviroManager.instance.Objects.additionalDirectionalLight.gameObject.GetComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalLightData>();
|
||||
|
||||
if(Settings.lightingMode == EnviroLighting.LightingMode.Single)
|
||||
{
|
||||
if(!EnviroManager.instance.isNight)
|
||||
{
|
||||
//Set light to sun
|
||||
EnviroManager.instance.Objects.directionalLight.transform.rotation = EnviroManager.instance.Objects.sun.transform.rotation;
|
||||
EnviroManager.instance.Objects.directionalLight.color = Settings.sunColorGradient.Evaluate(EnviroManager.instance.solarTime);
|
||||
EnviroManager.instance.Objects.directionalLight.useColorTemperature = true;
|
||||
EnviroManager.instance.Objects.directionalLight.colorTemperature = Settings.lightColorTemperatureHDRP.Evaluate(EnviroManager.instance.solarTime);
|
||||
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
EnviroManager.instance.Objects.directionalLight.intensity = Settings.sunIntensityCurve.Evaluate(EnviroManager.instance.solarTime) * Settings.lightIntensityHDRP * Settings.directLightIntensityModifier;
|
||||
#else
|
||||
if(directionalLightHDRP != null)
|
||||
directionalLightHDRP.SetIntensity(Settings.sunIntensityCurve.Evaluate(EnviroManager.instance.solarTime) * Settings.lightIntensityHDRP * Settings.directLightIntensityModifier);
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Set light to moon
|
||||
EnviroManager.instance.Objects.directionalLight.transform.rotation = EnviroManager.instance.Objects.moon.transform.rotation;
|
||||
EnviroManager.instance.Objects.directionalLight.color = Settings.moonColorGradient.Evaluate(EnviroManager.instance.lunarTime);
|
||||
EnviroManager.instance.Objects.directionalLight.useColorTemperature = true;
|
||||
EnviroManager.instance.Objects.directionalLight.colorTemperature = Settings.lightColorTemperatureHDRP.Evaluate(EnviroManager.instance.solarTime);
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
EnviroManager.instance.Objects.directionalLight.intensity = Settings.moonIntensityCurve.Evaluate(EnviroManager.instance.lunarTime) * Settings.lightIntensityHDRP* Settings.directLightIntensityModifier;
|
||||
#else
|
||||
if (directionalLightHDRP != null)
|
||||
directionalLightHDRP.SetIntensity(Settings.moonIntensityCurve.Evaluate(EnviroManager.instance.lunarTime) * Settings.lightIntensityHDRP * Settings.directLightIntensityModifier);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(directionalLightHDRP != null)
|
||||
directionalLightHDRP.shadowDimmer = Settings.shadowIntensity;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Sun
|
||||
EnviroManager.instance.Objects.directionalLight.transform.rotation = EnviroManager.instance.Objects.sun.transform.rotation;
|
||||
EnviroManager.instance.Objects.directionalLight.color = Settings.sunColorGradient.Evaluate(EnviroManager.instance.solarTime);
|
||||
EnviroManager.instance.Objects.directionalLight.useColorTemperature = true;
|
||||
EnviroManager.instance.Objects.directionalLight.colorTemperature = Settings.lightColorTemperatureHDRP.Evaluate(EnviroManager.instance.solarTime);
|
||||
|
||||
if(directionalLightHDRP != null)
|
||||
{
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
EnviroManager.instance.Objects.directionalLight.intensity = Settings.sunIntensityCurve.Evaluate(EnviroManager.instance.solarTime) * Settings.lightIntensityHDRP* Settings.directLightIntensityModifier;
|
||||
#else
|
||||
directionalLightHDRP.SetIntensity(Settings.sunIntensityCurve.Evaluate(EnviroManager.instance.solarTime) * Settings.lightIntensityHDRP * Settings.directLightIntensityModifier);
|
||||
#endif
|
||||
|
||||
directionalLightHDRP.shadowDimmer = Settings.shadowIntensity;
|
||||
}
|
||||
//Moon
|
||||
if(EnviroManager.instance.Objects.additionalDirectionalLight != null)
|
||||
{
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.transform.rotation = EnviroManager.instance.Objects.moon.transform.rotation;
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.color = Settings.moonColorGradient.Evaluate(EnviroManager.instance.lunarTime);
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.useColorTemperature = true;
|
||||
EnviroManager.instance.Objects.additionalDirectionalLight.colorTemperature = Settings.lightColorTemperatureHDRP.Evaluate(EnviroManager.instance.solarTime);
|
||||
}
|
||||
|
||||
if(additionalLightHDRP != null)
|
||||
{
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
EnviroManager.instance.Objects.directionalLight.intensity = Settings.moonIntensityCurve.Evaluate(EnviroManager.instance.lunarTime) * Settings.lightIntensityHDRP * Settings.directLightIntensityModifier;
|
||||
#else
|
||||
additionalLightHDRP.SetIntensity(Settings.moonIntensityCurve.Evaluate(EnviroManager.instance.lunarTime) * Settings.lightIntensityHDRP * Settings.directLightIntensityModifier);
|
||||
#endif
|
||||
|
||||
additionalLightHDRP.shadowDimmer = Settings.shadowIntensity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAmbientLightingHDRP ()
|
||||
{
|
||||
if(EnviroManager.instance.volumeHDRP != null && EnviroManager.instance.volumeProfileHDRP != null)
|
||||
{
|
||||
if(indirectLightingHDRP == null)
|
||||
{
|
||||
UnityEngine.Rendering.HighDefinition.IndirectLightingController TempIndirectLight;
|
||||
|
||||
if (EnviroManager.instance.volumeProfileHDRP.TryGet<UnityEngine.Rendering.HighDefinition.IndirectLightingController>(out TempIndirectLight))
|
||||
{
|
||||
indirectLightingHDRP = TempIndirectLight;
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.volumeProfileHDRP.Add<UnityEngine.Rendering.HighDefinition.IndirectLightingController>();
|
||||
|
||||
if (EnviroManager.instance.volumeProfileHDRP.TryGet<UnityEngine.Rendering.HighDefinition.IndirectLightingController>(out TempIndirectLight))
|
||||
{
|
||||
indirectLightingHDRP = TempIndirectLight;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Settings.controlIndirectLighting)
|
||||
{
|
||||
indirectLightingHDRP.active = true;
|
||||
indirectLightingHDRP.indirectDiffuseLightingMultiplier.overrideState = true;
|
||||
indirectLightingHDRP.indirectDiffuseLightingMultiplier.value = Settings.diffuseIndirectIntensity.Evaluate(EnviroManager.instance.solarTime);
|
||||
indirectLightingHDRP.reflectionLightingMultiplier.overrideState = true;
|
||||
indirectLightingHDRP.reflectionLightingMultiplier.value = Settings.reflectionIndirectIntensity.Evaluate(EnviroManager.instance.solarTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
indirectLightingHDRP.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateExposureHDRP ()
|
||||
{
|
||||
if(EnviroManager.instance.volumeHDRP != null && EnviroManager.instance.volumeProfileHDRP != null)
|
||||
{
|
||||
if(exposureHDRP == null)
|
||||
{
|
||||
UnityEngine.Rendering.HighDefinition.Exposure TempExposure;
|
||||
|
||||
if (EnviroManager.instance.volumeProfileHDRP.TryGet<UnityEngine.Rendering.HighDefinition.Exposure>(out TempExposure))
|
||||
{
|
||||
exposureHDRP = TempExposure;
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.volumeProfileHDRP.Add<UnityEngine.Rendering.HighDefinition.Exposure>();
|
||||
|
||||
if (EnviroManager.instance.volumeProfileHDRP.TryGet<UnityEngine.Rendering.HighDefinition.Exposure>(out TempExposure))
|
||||
{
|
||||
exposureHDRP = TempExposure;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Settings.controlExposure)
|
||||
{
|
||||
exposureHDRP.active = true;
|
||||
exposureHDRP.mode.overrideState = true;
|
||||
exposureHDRP.mode.value = UnityEngine.Rendering.HighDefinition.ExposureMode.Fixed;
|
||||
exposureHDRP.fixedExposure.overrideState = true;
|
||||
exposureHDRP.fixedExposure.value = Settings.sceneExposure.Evaluate(EnviroManager.instance.solarTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
exposureHDRP.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public void UpdateAmbientLighting (bool forced = false)
|
||||
{
|
||||
RenderSettings.ambientMode = Settings.ambientMode;
|
||||
|
||||
float intensity = Settings.ambientIntensityCurve.Evaluate(EnviroManager.instance.solarTime) * Settings.ambientIntensityModifier;
|
||||
|
||||
RenderSettings.ambientIntensity = intensity;
|
||||
|
||||
if(forced)
|
||||
{
|
||||
UpdateAmbient(Settings.ambientMode,intensity);
|
||||
|
||||
if(EnviroManager.instance.Time != null)
|
||||
{
|
||||
lastAmbientSkyboxUpdate = EnviroManager.instance.Time.Settings.timeOfDay + Settings.ambientUpdateIntervall;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(EnviroManager.instance.Time != null)
|
||||
{
|
||||
if (lastAmbientSkyboxUpdate < EnviroManager.instance.Time.Settings.timeOfDay || lastAmbientSkyboxUpdate > EnviroManager.instance.Time.Settings.timeOfDay + (Settings.ambientUpdateIntervall + 0.01f))
|
||||
{
|
||||
UpdateAmbient(Settings.ambientMode,intensity);
|
||||
lastAmbientSkyboxUpdate = EnviroManager.instance.Time.Settings.timeOfDay + Settings.ambientUpdateIntervall;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lastAmbientSkyboxUpdate < Time.time)
|
||||
{
|
||||
UpdateAmbient(Settings.ambientMode,intensity);
|
||||
lastAmbientSkyboxUpdate = Time.time + (Settings.ambientUpdateIntervall * 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAmbient(UnityEngine.Rendering.AmbientMode ambientMode, float intensity)
|
||||
{
|
||||
switch (ambientMode)
|
||||
{
|
||||
case UnityEngine.Rendering.AmbientMode.Flat:
|
||||
RenderSettings.ambientSkyColor = Settings.ambientSkyColorGradient.Evaluate(EnviroManager.instance.solarTime) * intensity;
|
||||
break;
|
||||
|
||||
case UnityEngine.Rendering.AmbientMode.Trilight:
|
||||
RenderSettings.ambientSkyColor = Settings.ambientSkyColorGradient.Evaluate(EnviroManager.instance.solarTime) * intensity;
|
||||
RenderSettings.ambientEquatorColor = Settings.ambientEquatorColorGradient.Evaluate(EnviroManager.instance.solarTime) * intensity;
|
||||
RenderSettings.ambientGroundColor = Settings.ambientGroundColorGradient.Evaluate(EnviroManager.instance.solarTime) * intensity;
|
||||
break;
|
||||
|
||||
case UnityEngine.Rendering.AmbientMode.Skybox:
|
||||
DynamicGI.UpdateEnvironment();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
Settings = JsonUtility.FromJson<Enviro.EnviroLighting>(JsonUtility.ToJson(preset.Settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroLightingModule t = ScriptableObject.CreateInstance<EnviroLightingModule>();
|
||||
t.name = "Lighting Module";
|
||||
t.Settings = JsonUtility.FromJson<Enviro.EnviroLighting>(JsonUtility.ToJson(Settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SaveModuleValues (EnviroLightingModule module)
|
||||
{
|
||||
module.Settings = JsonUtility.FromJson<Enviro.EnviroLighting>(JsonUtility.ToJson(Settings));
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b18a0693e95fd064e9d0a3b96e538236
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Lighting/EnviroLightingModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43d2103184b3c9b4a9f920958db18b55
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,542 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b18a0693e95fd064e9d0a3b96e538236, type: 3}
|
||||
m_Name: Default Lighting Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 1
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
Settings:
|
||||
lightingMode: 0
|
||||
setDirectLighting: 1
|
||||
updateIntervallFrames: 1
|
||||
sunIntensityCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.42
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.5817692
|
||||
value: 1.9319578
|
||||
inSlope: 0.20075521
|
||||
outSlope: 0.20075521
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.99427843
|
||||
value: 1.9724423
|
||||
inSlope: 0.138579
|
||||
outSlope: 0.138579
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33801654
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
moonIntensityCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.42
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.61047
|
||||
value: 0.46311775
|
||||
inSlope: 0.20075521
|
||||
outSlope: 0.20075521
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.9869074
|
||||
value: 0.49453083
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
sunColorGradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0.29803923, g: 0.33333334, b: 0.4392157, a: 1}
|
||||
key1: {r: 0.3853806, g: 0.4379325, b: 0.5955882, a: 1}
|
||||
key2: {r: 1, g: 0.51851845, b: 0, a: 0}
|
||||
key3: {r: 0.91764706, g: 0.78431374, b: 0.6431373, a: 0}
|
||||
key4: {r: 0.91764706, g: 0.8627451, b: 0.80784315, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 29491
|
||||
ctime2: 33153
|
||||
ctime3: 36700
|
||||
ctime4: 65535
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 5
|
||||
m_NumAlphaKeys: 2
|
||||
moonColorGradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0, g: 0, b: 0, a: 1}
|
||||
key1: {r: 0.009433985, g: 0.009433985, b: 0.009433985, a: 1}
|
||||
key2: {r: 0.35844606, g: 0.38487896, b: 0.4245283, a: 0}
|
||||
key3: {r: 0.45990568, g: 0.5011793, b: 0.6132076, a: 0}
|
||||
key4: {r: 0, g: 0, b: 0, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 29491
|
||||
ctime2: 33539
|
||||
ctime3: 65535
|
||||
ctime4: 0
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 4
|
||||
m_NumAlphaKeys: 2
|
||||
sunIntensityCurveHDRP:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: -0.005858557
|
||||
value: 0
|
||||
inSlope: -69.7483
|
||||
outSlope: -69.7483
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.28545874
|
||||
- serializedVersion: 3
|
||||
time: 0.42
|
||||
value: 0
|
||||
inSlope: -14.224594
|
||||
outSlope: -14.224594
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.16805899
|
||||
outWeight: 0.5635239
|
||||
- serializedVersion: 3
|
||||
time: 0.51438606
|
||||
value: 619.9909
|
||||
inSlope: 14358.117
|
||||
outSlope: 14358.117
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.12846851
|
||||
outWeight: 0.20660013
|
||||
- serializedVersion: 3
|
||||
time: 0.6068845
|
||||
value: 1314.4552
|
||||
inSlope: 1486.1951
|
||||
outSlope: 1486.1951
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.330822
|
||||
outWeight: 0.16775069
|
||||
- serializedVersion: 3
|
||||
time: 1.0073586
|
||||
value: 1497.6918
|
||||
inSlope: -142.08925
|
||||
outSlope: -142.08925
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.18685488
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
moonIntensityCurveHDRP:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.42
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 1
|
||||
- serializedVersion: 3
|
||||
time: 0.5151054
|
||||
value: 29.550873
|
||||
inSlope: 936.90796
|
||||
outSlope: 936.90796
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.42325592
|
||||
outWeight: 0.25243106
|
||||
- serializedVersion: 3
|
||||
time: 0.5727867
|
||||
value: 65.81247
|
||||
inSlope: 153.72064
|
||||
outSlope: 153.72064
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.3182723
|
||||
outWeight: 0.17477258
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 89.63618
|
||||
inSlope: 0.074095555
|
||||
outSlope: 0.074095555
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.14896
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
lightColorTemperatureHDRP:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0.0042874366
|
||||
value: 10002.518
|
||||
inSlope: -65.305664
|
||||
outSlope: -65.305664
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.38720584
|
||||
value: 9894.908
|
||||
inSlope: -855.4398
|
||||
outSlope: -855.4398
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.4745867
|
||||
value: 2850.5876
|
||||
inSlope: 926.3545
|
||||
outSlope: 926.3545
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.6485079
|
||||
value: 4931.462
|
||||
inSlope: 4445.381
|
||||
outSlope: 4445.381
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1.0041809
|
||||
value: 5500
|
||||
inSlope: 93.2233
|
||||
outSlope: 93.2233
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
ambientColorTintHDRP:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0.8867924, g: 0.8867924, b: 0.8867924, a: 1}
|
||||
key1: {r: 0.9056604, g: 0.9013884, b: 0.9013884, a: 1}
|
||||
key2: {r: 2, g: 2, b: 2, a: 0.78431374}
|
||||
key3: {r: 0, g: 0, b: 0, a: 0.78431374}
|
||||
key4: {r: 0, g: 0, b: 0, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 65535
|
||||
ctime2: 65535
|
||||
ctime3: 0
|
||||
ctime4: 0
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 65535
|
||||
atime3: 65535
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 2
|
||||
m_NumAlphaKeys: 2
|
||||
lightIntensityHDRP: 350
|
||||
controlExposure: 1
|
||||
sceneExposure:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 5
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 5
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
controlIndirectLighting: 1
|
||||
diffuseIndirectIntensity:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
reflectionIndirectIntensity:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
directLightIntensityModifier: 1
|
||||
setAmbientLighting: 1
|
||||
ambientMode: 0
|
||||
ambientSkyColorGradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0, g: 0, b: 0, a: 1}
|
||||
key1: {r: 0.010946958, g: 0.015512637, b: 0.05660379, a: 1}
|
||||
key2: {r: 0.17475082, g: 0.18796726, b: 0.31132078, a: 0}
|
||||
key3: {r: 0.33931115, g: 0.43156135, b: 0.5754717, a: 0}
|
||||
key4: {r: 0.5298594, g: 0.60636276, b: 0.764151, a: 0}
|
||||
key5: {r: 0.5298594, g: 0.60636276, b: 0.764151, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 15360
|
||||
ctime2: 29593
|
||||
ctime3: 36556
|
||||
ctime4: 65535
|
||||
ctime5: 65535
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 5
|
||||
m_NumAlphaKeys: 2
|
||||
ambientEquatorColorGradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0, g: 0, b: 0, a: 1}
|
||||
key1: {r: 0.010946958, g: 0.015512637, b: 0.05660379, a: 1}
|
||||
key2: {r: 0.15356888, g: 0.16649368, b: 0.2735849, a: 0}
|
||||
key3: {r: 0.33931115, g: 0.43156135, b: 0.5754717, a: 0}
|
||||
key4: {r: 0.5298594, g: 0.60636276, b: 0.764151, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 15360
|
||||
ctime2: 29593
|
||||
ctime3: 36556
|
||||
ctime4: 65535
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 5
|
||||
m_NumAlphaKeys: 2
|
||||
ambientGroundColorGradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0, g: 0, b: 0, a: 1}
|
||||
key1: {r: 0.010946958, g: 0.015512637, b: 0.05660379, a: 1}
|
||||
key2: {r: 0.15356888, g: 0.16649368, b: 0.2735849, a: 0}
|
||||
key3: {r: 0.33931115, g: 0.43156135, b: 0.5754717, a: 0}
|
||||
key4: {r: 0.5298594, g: 0.60636276, b: 0.764151, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 15360
|
||||
ctime2: 29593
|
||||
ctime3: 36556
|
||||
ctime4: 65535
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 5
|
||||
m_NumAlphaKeys: 2
|
||||
ambientIntensityCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: -0.021333456
|
||||
value: 0.8050667
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
- serializedVersion: 3
|
||||
time: 0.97866654
|
||||
value: 0.8050667
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
ambientIntensityModifier: 1
|
||||
ambientUpdateEveryFrame: 0
|
||||
ambientUpdateIntervall: 0.1
|
||||
shadowIntensity: 0.996
|
||||
preset: {fileID: 0}
|
||||
showDirectLightingControls: 0
|
||||
showAmbientLightingControls: 0
|
||||
showReflectionControls: 0
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81d8b109102443243bcb0894975c0718
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Lighting/Preset/Default
|
||||
Lighting Preset.asset
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c3b7ecd7d94a254bb2c730b1f0ab9ca
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,184 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for a lightning effect.
|
||||
/// </summary>
|
||||
public interface ILightningEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// Casts the bolt.
|
||||
/// </summary>
|
||||
/// <param name="origin">The starting position of the bolt.</param>
|
||||
/// <param name="target">The target position of the bolt.</param>
|
||||
void CastBolt(Vector3 origin, Vector3 target);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroLightning
|
||||
{
|
||||
public Lightning prefab;
|
||||
public GameObject customLightningEffect;
|
||||
|
||||
public bool lightningStorm = false;
|
||||
[Range(1f,60f)]
|
||||
public float randomLightingDelay = 10.0f;
|
||||
[Range(0f,10000f)]
|
||||
public float randomSpawnRange = 5000.0f;
|
||||
[Range(0f,10000f)]
|
||||
public float randomTargetRange = 5000.0f;
|
||||
|
||||
[Range(0f,10000f)]
|
||||
public float cloudsLightningRadius = 2500.0f;
|
||||
[Range(.1f,5f)]
|
||||
public float cloudsLightningDuration = 1.0f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroLightningModule : EnviroModule
|
||||
{
|
||||
public EnviroLightning Settings;
|
||||
public EnviroLightningModule preset;
|
||||
public bool showLightningControls;
|
||||
private bool spawned = false;
|
||||
|
||||
private float lightningStart = -999f;
|
||||
|
||||
// Update Method
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
if(!active)
|
||||
return;
|
||||
|
||||
if(Application.isPlaying && Settings.lightningStorm && Settings.prefab != null)
|
||||
{
|
||||
CastLightningBoltRandom();
|
||||
}
|
||||
}
|
||||
|
||||
public void CastLightningBolt(Vector3 from, Vector3 to)
|
||||
{
|
||||
if(Settings.prefab != null)
|
||||
{
|
||||
GameObject lightningGameObject;
|
||||
if (Settings.customLightningEffect != null)
|
||||
{
|
||||
lightningGameObject = Instantiate(Settings.customLightningEffect, from, Quaternion.identity);
|
||||
}
|
||||
else
|
||||
{
|
||||
lightningGameObject = Instantiate(Settings.prefab, from, Quaternion.identity).gameObject;
|
||||
}
|
||||
|
||||
var lightningEffect = lightningGameObject.GetComponent<ILightningEffect>();
|
||||
lightningEffect.CastBolt(from, to);
|
||||
|
||||
|
||||
//Play Thunder SFX with delay if Audio module is used.
|
||||
if (EnviroManager.instance.Audio != null)
|
||||
{
|
||||
EnviroManager.instance.StartCoroutine(PlayThunderSFX(0.05f));
|
||||
}
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
{
|
||||
EnviroManager.instance.StartCoroutine(CloudsFlash(0.25f,from));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a lightning prefab in your Enviro Ligthning module!");
|
||||
}
|
||||
}
|
||||
|
||||
public void CastLightningBoltRandom()
|
||||
{
|
||||
if(!spawned)
|
||||
{
|
||||
//Calculate some random spawn and target locations.
|
||||
Vector2 circlSpawn = UnityEngine.Random.insideUnitCircle * Settings.randomSpawnRange;
|
||||
Vector2 circlTarget = UnityEngine.Random.insideUnitCircle * Settings.randomTargetRange;
|
||||
float offset = 0f;
|
||||
|
||||
if(EnviroManager.instance.Objects.worldAnchor != null)
|
||||
offset = EnviroManager.instance.Objects.worldAnchor.transform.position.y;
|
||||
|
||||
float altitude = 2000f;
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
altitude = Mathf.Max(EnviroManager.instance.VolumetricClouds.settingsVolume.bottomCloudsHeight + 1000f, 1000f);
|
||||
|
||||
Vector3 spawnPosition = new Vector3(circlSpawn.x + EnviroManager.instance.transform.position.x, offset + altitude, circlSpawn.y + EnviroManager.instance.transform.position.z);
|
||||
Vector3 targetPosition = new Vector3(circlTarget.x + spawnPosition.x,offset,circlTarget.y + spawnPosition.z);
|
||||
|
||||
EnviroManager.instance.StartCoroutine(LightningStorm(spawnPosition,targetPosition));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator LightningStorm(Vector3 spwn, Vector3 targ)
|
||||
{
|
||||
spawned = true;
|
||||
CastLightningBolt(spwn,targ);
|
||||
yield return new WaitForSeconds(UnityEngine.Random.Range(Settings.randomLightingDelay, Settings.randomLightingDelay * 2f));
|
||||
spawned = false;
|
||||
}
|
||||
|
||||
private IEnumerator PlayThunderSFX(float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
EnviroManager.instance.Audio.PlayRandomThunderSFX();
|
||||
}
|
||||
private IEnumerator CloudsFlash(float delay, Vector3 from)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
//Clouds
|
||||
lightningStart = Time.time;
|
||||
|
||||
// Pass to shader each frame
|
||||
Shader.SetGlobalVector("_LightningCenter", from);
|
||||
Shader.SetGlobalFloat("_LightningRadius", Settings.cloudsLightningRadius);
|
||||
Shader.SetGlobalFloat("_LightningStart", lightningStart);
|
||||
Shader.SetGlobalFloat("_LightningDuration", Settings.cloudsLightningDuration);
|
||||
}
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
Settings = JsonUtility.FromJson<Enviro.EnviroLightning>(JsonUtility.ToJson(preset.Settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroLightningModule t = ScriptableObject.CreateInstance<EnviroLightningModule>();
|
||||
t.name = "Lightning Preset";
|
||||
t.Settings = JsonUtility.FromJson<Enviro.EnviroLightning>(JsonUtility.ToJson(Settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
public void SaveModuleValues (EnviroLightningModule module)
|
||||
{
|
||||
module.Settings = JsonUtility.FromJson<Enviro.EnviroLightning>(JsonUtility.ToJson(Settings));
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 258de2724c9dfb643a546d0688715ff1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Lightning/EnviroLightningModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,182 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
|
||||
public class Lightning : MonoBehaviour, ILightningEffect
|
||||
{
|
||||
public void CastBolt(Vector3 origin, Vector3 target)
|
||||
{
|
||||
this.transform.position = origin;
|
||||
this.target = target;
|
||||
this.CastBolt();
|
||||
}
|
||||
|
||||
public float flashIntensity = 50f;
|
||||
public Vector3 target;
|
||||
private LineRenderer lineRend;
|
||||
public Light myLight;
|
||||
public Material planeMat;
|
||||
public int arcs = 20;
|
||||
public float arcLength = 100.0f;
|
||||
public float arcVariation = 1.0f;
|
||||
public float inaccuracy = 0.5f;
|
||||
public int splits = 4;
|
||||
public int maxSplits = 24;
|
||||
private int splitCount = 0;
|
||||
public float splitLength = 100.0f;
|
||||
public float splitVariation = 1.0f;
|
||||
|
||||
public Vector3 toTarget;
|
||||
private bool fadeOut;
|
||||
private float fadeTimer;
|
||||
|
||||
void OnEnable ()
|
||||
{
|
||||
lineRend = gameObject.GetComponent<LineRenderer> ();
|
||||
}
|
||||
|
||||
IEnumerator CreateLightningBolt()
|
||||
{
|
||||
myLight.enabled = false;
|
||||
lineRend.widthMultiplier = 10;
|
||||
planeMat.SetFloat("_Brightness", 1f);
|
||||
|
||||
|
||||
lineRend.SetPosition(0, transform.position);
|
||||
lineRend.positionCount = 2;
|
||||
lineRend.SetPosition(1, transform.position);
|
||||
Vector3 lastPoint = transform.position;
|
||||
float dist = Vector3.Distance(transform.position, target);
|
||||
|
||||
float arcDist = dist / arcs;
|
||||
|
||||
for (int i = 1; i < arcs; i++)
|
||||
{
|
||||
planeMat.SetFloat("_Brightness", Random.Range(0f,2f));
|
||||
lineRend.positionCount = i + 1;
|
||||
Vector3 fwd = target - lastPoint;
|
||||
fwd.Normalize ();
|
||||
Vector3 pos = Randomize (fwd, inaccuracy);
|
||||
pos *= Random.Range (arcLength * arcVariation, arcLength) * (arcDist);
|
||||
pos += lastPoint;
|
||||
lineRend.SetPosition (i, pos);
|
||||
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
for (int s = 0; s <= splits; s++)
|
||||
{
|
||||
if(splitCount < maxSplits)
|
||||
StartCoroutine(CreateSplit(pos, target));
|
||||
}
|
||||
}
|
||||
|
||||
lastPoint = pos;
|
||||
// yield return new WaitForSeconds(Random.Range(0.001f,0.005f));
|
||||
}
|
||||
yield return new WaitForSeconds(Random.Range(0.1f,0.2f));
|
||||
lineRend.SetPosition(arcs-1,target);
|
||||
|
||||
//Animate Light and Main bolt
|
||||
myLight.transform.position = target;
|
||||
|
||||
if(EnviroManager.instance.Camera != null)
|
||||
myLight.transform.LookAt(EnviroManager.instance.Camera.transform.position, Vector3.up);
|
||||
|
||||
lineRend.material.SetFloat("_Brightness", this.flashIntensity);
|
||||
planeMat.SetFloat("_Brightness", 20f);
|
||||
myLight.enabled = true;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
lineRend.material.SetFloat("_Brightness", 1f);
|
||||
planeMat.SetFloat("_Brightness", 1f);
|
||||
myLight.enabled = false;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
lineRend.material.SetFloat("_Brightness", this.flashIntensity);
|
||||
planeMat.SetFloat("_Brightness", 20f);
|
||||
myLight.enabled = true;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
lineRend.material.SetFloat("_Brightness", 1f);
|
||||
planeMat.SetFloat("_Brightness", 1f);
|
||||
myLight.enabled = false;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
lineRend.material.SetFloat("_Brightness", this.flashIntensity);
|
||||
planeMat.SetFloat("_Brightness", 0f);
|
||||
myLight.enabled = true;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
myLight.enabled = false;
|
||||
fadeTimer = 50f;
|
||||
fadeOut = true;
|
||||
}
|
||||
|
||||
IEnumerator CreateSplit(Vector3 pos, Vector3 targetP)
|
||||
{
|
||||
splitCount++;
|
||||
GameObject split = new GameObject();
|
||||
split.transform.SetParent(transform);
|
||||
split.transform.position = pos;
|
||||
LineRenderer splitRenderer = split.AddComponent<LineRenderer>();
|
||||
splitRenderer.material = lineRend.material;
|
||||
splitRenderer.material.SetFloat("_Brightness", flashIntensity * 0.9f);
|
||||
splitRenderer.positionCount = 2;
|
||||
splitRenderer.SetPosition(0, split.transform.position);
|
||||
splitRenderer.SetPosition(1, split.transform.position);
|
||||
|
||||
//Set a random target
|
||||
toTarget = targetP - pos;
|
||||
toTarget = Vector3.Normalize(toTarget);
|
||||
Vector3 posDown = new Vector3(toTarget.x,toTarget.y, toTarget.z * 0.1f);
|
||||
Vector3 targetPos = (Random.insideUnitSphere * 500 + pos + toTarget * 800);
|
||||
|
||||
Vector3 lastPoint = split.transform.position;
|
||||
float dist = Vector3.Distance(split.transform.position, targetPos);
|
||||
|
||||
float arcDist = dist / 32;
|
||||
|
||||
for (int i = 1; i < 16; i++)
|
||||
{
|
||||
splitRenderer.positionCount = i + 1;
|
||||
Vector3 fwd = targetPos - lastPoint;
|
||||
fwd.Normalize ();
|
||||
Vector3 newPos = Randomize (fwd, inaccuracy);
|
||||
|
||||
newPos *= Random.Range (splitLength * splitVariation, splitLength) * (arcDist);
|
||||
newPos += lastPoint;
|
||||
splitRenderer.SetPosition (i, newPos);
|
||||
lastPoint = newPos;
|
||||
yield return new WaitForSeconds(Random.Range(0.004f,0.006f));
|
||||
}
|
||||
splitRenderer.SetPosition(7,targetPos);
|
||||
yield return new WaitForSeconds(Random.Range(0.2f,0.5f));
|
||||
DestroyImmediate(split);
|
||||
}
|
||||
|
||||
public void CastBolt()
|
||||
{
|
||||
lineRend.positionCount = 1;
|
||||
StartCoroutine(CreateLightningBolt());
|
||||
}
|
||||
private Vector3 Randomize (Vector3 newVector, float devation) {
|
||||
newVector += new Vector3(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f)) * devation;
|
||||
newVector.Normalize();
|
||||
return newVector;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(fadeOut == true)
|
||||
{
|
||||
fadeTimer = Mathf.Lerp(fadeTimer,0f,10f * Time.deltaTime);
|
||||
lineRend.material.SetFloat("_Brightness", fadeTimer);
|
||||
|
||||
if(fadeTimer <= 1f)
|
||||
{
|
||||
lineRend.positionCount = 1;
|
||||
fadeOut = false;
|
||||
DestroyImmediate(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07501689299c0de43b5f4c0e6edd5bbd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Lightning/Lightning.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 569473d5f2a90ed4194c55a1ec36cd93
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 258de2724c9dfb643a546d0688715ff1, type: 3}
|
||||
m_Name: Default Lightning Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 0
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
Settings:
|
||||
prefab: {fileID: 8233971941884837668, guid: 3686e34c2aa90c44e8eab718f3bf99b6, type: 3}
|
||||
customLightningEffect: {fileID: 0}
|
||||
lightningStorm: 0
|
||||
randomLightingDelay: 1
|
||||
randomSpawnRange: 5000
|
||||
randomTargetRange: 5000
|
||||
cloudsLightningRadius: 2000
|
||||
cloudsLightningDuration: 0.5
|
||||
preset: {fileID: 0}
|
||||
showLightningControls: 0
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9a0f93373ad7014fbe96d77c75cbe4e
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Lightning/Preset/Default
|
||||
Lightning Preset.asset
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 991b756a2cc2fbd47b2216455c853139
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,101 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroSkyQualitySettings
|
||||
{
|
||||
public EnviroSky.SkyMode skyMode = EnviroSky.SkyMode.Normal;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroVolumetricCloudsQualitySettings
|
||||
{
|
||||
public bool volumetricClouds = true;
|
||||
public bool lightningSupport = true;
|
||||
public bool variableBottomNoise = false;
|
||||
|
||||
public int downsampling = 4;
|
||||
public int stepsLayer1 = 128;
|
||||
public float blueNoiseIntensity = 1f;
|
||||
public float reprojectionBlendTime = 10f;
|
||||
public float lodDistance = 0.25f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroFlatCloudsQualitySettings
|
||||
{
|
||||
public bool cirrusClouds = true;
|
||||
public bool flatClouds = true;
|
||||
public int flatCloudsShadowSteps = 8;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroAuroraQualitySettings
|
||||
{
|
||||
public bool aurora = true;
|
||||
[Range(6,32)]
|
||||
public int steps = 32;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroEffectsQualitySettings
|
||||
{
|
||||
[Range(0f,2f)]
|
||||
public float particeEmissionRateModifier = 1f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroFogQualitySettings
|
||||
{
|
||||
public bool fog = true;
|
||||
public EnviroFogSettings.FogQualityMode fogQualityMode = EnviroFogSettings.FogQualityMode.Normal;
|
||||
public bool volumetrics = true;
|
||||
public bool unityFog = false;
|
||||
public EnviroFogSettings.Quality quality;
|
||||
[Range(16,96)]
|
||||
public int steps = 32;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroQuality : ScriptableObject
|
||||
{
|
||||
//Inspector
|
||||
public bool showEditor, showSky, showVolumeClouds, showFog, showFlatClouds, showEffects, showAurora;
|
||||
public EnviroSkyQualitySettings skyOverride;
|
||||
public EnviroVolumetricCloudsQualitySettings volumetricCloudsOverride;
|
||||
public EnviroFogQualitySettings fogOverride;
|
||||
public EnviroFlatCloudsQualitySettings flatCloudsOverride;
|
||||
public EnviroAuroraQualitySettings auroraOverride;
|
||||
public EnviroEffectsQualitySettings effectsOverride;
|
||||
}
|
||||
|
||||
|
||||
public class EnviroQualityCreation
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("Assets/Create/Enviro3/Quality")]
|
||||
#endif
|
||||
public static EnviroQuality CreateMyAsset()
|
||||
{
|
||||
EnviroQuality wpreset = ScriptableObject.CreateInstance<EnviroQuality>();
|
||||
#if UNITY_EDITOR
|
||||
// Create and save the new profile with unique name
|
||||
string path = UnityEditor.AssetDatabase.GetAssetPath (UnityEditor.Selection.activeObject);
|
||||
if (path == "")
|
||||
{
|
||||
path = EnviroHelper.assetPath;
|
||||
}
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath (path + "/New " + "Quality" + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset (wpreset, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets ();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
return wpreset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfcd10a1b99270a488a19072f6176530
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Quality/EnviroQuality.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,160 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroQualities
|
||||
{
|
||||
public EnviroQuality defaultQuality;
|
||||
public List<EnviroQuality> Qualities = new List<EnviroQuality>();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroQualityModule : EnviroModule
|
||||
{
|
||||
public EnviroQualities Settings = new EnviroQualities();
|
||||
public EnviroQualityModule preset;
|
||||
public bool showQualityControls;
|
||||
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
//Make sure that we always have at least one quality profile!
|
||||
if(Settings.defaultQuality == null)
|
||||
{
|
||||
if(Settings.Qualities.Count > 0)
|
||||
{
|
||||
Settings.defaultQuality = Settings.Qualities[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateNewQuality();
|
||||
Settings.defaultQuality = Settings.Qualities[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
if(Settings.defaultQuality != null)
|
||||
{
|
||||
if(EnviroManager.instance.Sky != null)
|
||||
{
|
||||
EnviroManager.instance.Sky.Settings.skyMode = Settings.defaultQuality.skyOverride.skyMode;
|
||||
}
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
{
|
||||
EnviroManager.instance.VolumetricClouds.settingsQuality.volumetricClouds = Settings.defaultQuality.volumetricCloudsOverride.volumetricClouds;
|
||||
EnviroManager.instance.VolumetricClouds.settingsQuality.lightningSupport = Settings.defaultQuality.volumetricCloudsOverride.lightningSupport;
|
||||
EnviroManager.instance.VolumetricClouds.settingsQuality.variableBottomNoise = Settings.defaultQuality.volumetricCloudsOverride.variableBottomNoise;
|
||||
EnviroManager.instance.VolumetricClouds.settingsQuality.downsampling = Settings.defaultQuality.volumetricCloudsOverride.downsampling;
|
||||
EnviroManager.instance.VolumetricClouds.settingsQuality.stepsLayer1 = Settings.defaultQuality.volumetricCloudsOverride.stepsLayer1;
|
||||
EnviroManager.instance.VolumetricClouds.settingsQuality.blueNoiseIntensity = Settings.defaultQuality.volumetricCloudsOverride.blueNoiseIntensity;
|
||||
EnviroManager.instance.VolumetricClouds.settingsQuality.reprojectionBlendTime = Settings.defaultQuality.volumetricCloudsOverride.reprojectionBlendTime;
|
||||
EnviroManager.instance.VolumetricClouds.settingsQuality.lodDistance = Settings.defaultQuality.volumetricCloudsOverride.lodDistance;
|
||||
}
|
||||
|
||||
if(EnviroManager.instance.Fog != null)
|
||||
{
|
||||
EnviroManager.instance.Fog.Settings.fog = Settings.defaultQuality.fogOverride.fog;
|
||||
EnviroManager.instance.Fog.Settings.fogQualityMode = Settings.defaultQuality.fogOverride.fogQualityMode;
|
||||
EnviroManager.instance.Fog.Settings.volumetrics = Settings.defaultQuality.fogOverride.volumetrics;
|
||||
EnviroManager.instance.Fog.Settings.unityFog = Settings.defaultQuality.fogOverride.unityFog;
|
||||
EnviroManager.instance.Fog.Settings.quality = Settings.defaultQuality.fogOverride.quality;
|
||||
EnviroManager.instance.Fog.Settings.steps = Settings.defaultQuality.fogOverride.steps;
|
||||
}
|
||||
|
||||
if(EnviroManager.instance.FlatClouds != null)
|
||||
{
|
||||
EnviroManager.instance.FlatClouds.settings.useFlatClouds = Settings.defaultQuality.flatCloudsOverride.flatClouds;
|
||||
EnviroManager.instance.FlatClouds.settings.useCirrusClouds = Settings.defaultQuality.flatCloudsOverride.cirrusClouds;
|
||||
EnviroManager.instance.FlatClouds.settings.flatCloudsShadowSteps = Settings.defaultQuality.flatCloudsOverride.flatCloudsShadowSteps;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(EnviroManager.instance.Aurora != null)
|
||||
{
|
||||
EnviroManager.instance.Aurora.Settings.useAurora = Settings.defaultQuality.auroraOverride.aurora;
|
||||
EnviroManager.instance.Aurora.Settings.auroraSteps = Settings.defaultQuality.auroraOverride.steps;
|
||||
}
|
||||
|
||||
if(EnviroManager.instance.Effects != null)
|
||||
{
|
||||
EnviroManager.instance.Effects.Settings.particeEmissionRateModifier = Settings.defaultQuality.effectsOverride.particeEmissionRateModifier;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CleanupQualityList()
|
||||
{
|
||||
for (int i = 0; i < Settings.Qualities.Count; i++)
|
||||
{
|
||||
if(Settings.Qualities[i] == null)
|
||||
Settings.Qualities.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
//Add new or assigned quality
|
||||
public void CreateNewQuality()
|
||||
{
|
||||
EnviroQuality quality = EnviroQualityCreation.CreateMyAsset();
|
||||
Settings.Qualities.Add(quality);
|
||||
}
|
||||
|
||||
/// Removes the quality from the list.
|
||||
public void RemoveQuality(EnviroQuality quality)
|
||||
{
|
||||
Settings.Qualities.Remove(quality);
|
||||
}
|
||||
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
Settings = JsonUtility.FromJson<Enviro.EnviroQualities>(JsonUtility.ToJson(preset.Settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroQualityModule t = ScriptableObject.CreateInstance<EnviroQualityModule>();
|
||||
t.name = "Quality Module Preset";
|
||||
t.Settings = JsonUtility.FromJson<Enviro.EnviroQualities>(JsonUtility.ToJson(Settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
public void SaveModuleValues (EnviroQualityModule module)
|
||||
{
|
||||
module.Settings = JsonUtility.FromJson<Enviro.EnviroQualities>(JsonUtility.ToJson(Settings));
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 456bf221b186fde4096dcf2c1841b35a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Quality/EnviroQualityModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0fd49af59609e246bc7e5be19f334f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 456bf221b186fde4096dcf2c1841b35a, type: 3}
|
||||
m_Name: Default Quality Module Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 0
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
Settings:
|
||||
defaultQuality: {fileID: 11400000, guid: 60e887b1524da0a4a8f1318ef102e22a, type: 2}
|
||||
Qualities:
|
||||
- {fileID: 11400000, guid: a002704085c17f1439758fcee25df529, type: 2}
|
||||
- {fileID: 11400000, guid: 2e0aaa075bca92245a9e8300b7eace9c, type: 2}
|
||||
- {fileID: 11400000, guid: 60e887b1524da0a4a8f1318ef102e22a, type: 2}
|
||||
- {fileID: 11400000, guid: e653a1dee3c47bb42a13eba46069720c, type: 2}
|
||||
- {fileID: 11400000, guid: ce2712a713d73094fa9c2775886f182d, type: 2}
|
||||
preset: {fileID: 0}
|
||||
showQualityControls: 0
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87fc95b058753524e807e3f229e77c2f
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Quality/Preset/Default
|
||||
Quality Module Preset.asset
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f634272e68ed184c8abe120f7a02bbc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,672 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
#if ENVIRO_HDRP
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
#endif
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[AddComponentMenu("Enviro 3/Reflection Probe")]
|
||||
[RequireComponent(typeof(ReflectionProbe)), ExecuteInEditMode]
|
||||
public class EnviroReflectionProbe : MonoBehaviour
|
||||
{
|
||||
#region Public Var
|
||||
#region Standalone Settings
|
||||
public bool standalone = false;
|
||||
public bool updateReflectionOnGameTime = true;
|
||||
public float reflectionsUpdateTreshhold = 0.025f;
|
||||
public bool useTimeSlicing = true;
|
||||
#endregion
|
||||
public Camera renderCam;
|
||||
[HideInInspector]
|
||||
public ReflectionProbe myProbe;
|
||||
public bool customRendering = false;
|
||||
|
||||
#if !ENVIRO_HDRP
|
||||
private EnviroRenderer enviroRenderer;
|
||||
#endif
|
||||
public bool useFog = false;
|
||||
#endregion
|
||||
|
||||
#region Private Var
|
||||
// Privates
|
||||
public Camera bakingCam;
|
||||
public int renderId = -1;
|
||||
private bool currentMode = false;
|
||||
private int currentRes;
|
||||
private RenderTexture cubemap;
|
||||
private RenderTexture finalCubemap;
|
||||
private RenderTexture mirrorTexture;
|
||||
private RenderTexture renderTexture;
|
||||
private GameObject renderCamObj;
|
||||
private Material mirror = null;
|
||||
private Material bakeMat = null;
|
||||
private Material convolutionMat;
|
||||
private Coroutine refreshing;
|
||||
|
||||
private int renderID;
|
||||
|
||||
#if ENVIRO_HDRP
|
||||
public HDProbe hdprobe;
|
||||
#endif
|
||||
private static Quaternion[] orientations = new Quaternion[]
|
||||
{
|
||||
Quaternion.LookRotation(Vector3.right, Vector3.down),
|
||||
Quaternion.LookRotation(Vector3.left, Vector3.down),
|
||||
Quaternion.LookRotation(Vector3.up, Vector3.forward),
|
||||
Quaternion.LookRotation(Vector3.down, Vector3.back),
|
||||
Quaternion.LookRotation(Vector3.forward, Vector3.down),
|
||||
Quaternion.LookRotation(Vector3.back, Vector3.down)
|
||||
};
|
||||
|
||||
private double lastRelfectionUpdate;
|
||||
#endregion
|
||||
////////
|
||||
void OnEnable()
|
||||
{
|
||||
myProbe = GetComponent<ReflectionProbe>();
|
||||
|
||||
#if ENVIRO_HDRP
|
||||
if (EnviroManager.instance != null)
|
||||
{
|
||||
hdprobe = GetComponent<HDProbe>();
|
||||
|
||||
if(!standalone && myProbe != null)
|
||||
myProbe.enabled = true;
|
||||
|
||||
if (customRendering)
|
||||
{
|
||||
if (hdprobe != null)
|
||||
{
|
||||
hdprobe.mode = ProbeSettings.Mode.Custom;
|
||||
CreateCubemap();
|
||||
CreateTexturesAndMaterial();
|
||||
CreateRenderCamera();
|
||||
currentRes = myProbe.resolution;
|
||||
StartCoroutine(RefreshFirstTime());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hdprobe != null)
|
||||
{
|
||||
hdprobe.mode = ProbeSettings.Mode.Realtime;
|
||||
hdprobe.realtimeMode = ProbeSettings.RealtimeMode.OnDemand;
|
||||
hdprobe.RequestRenderNextUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
if (!standalone && myProbe != null)
|
||||
myProbe.enabled = true;
|
||||
|
||||
|
||||
if (customRendering)
|
||||
{
|
||||
myProbe.mode = ReflectionProbeMode.Custom;
|
||||
myProbe.refreshMode = ReflectionProbeRefreshMode.ViaScripting;
|
||||
CreateCubemap();
|
||||
CreateTexturesAndMaterial();
|
||||
CreateRenderCamera();
|
||||
currentRes = myProbe.resolution;
|
||||
StartCoroutine(RefreshFirstTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
myProbe.mode = ReflectionProbeMode.Realtime;
|
||||
myProbe.refreshMode = ReflectionProbeRefreshMode.ViaScripting;
|
||||
//StartCoroutine(RefreshUnity());
|
||||
renderId = myProbe.RenderProbe();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
Cleanup();
|
||||
|
||||
if (!standalone && myProbe != null)
|
||||
myProbe.enabled = false;
|
||||
|
||||
RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Skybox;
|
||||
}
|
||||
private void Cleanup()
|
||||
{
|
||||
if (refreshing != null)
|
||||
StopCoroutine(refreshing);
|
||||
|
||||
if (cubemap != null)
|
||||
{
|
||||
if (renderCam != null)
|
||||
renderCam.targetTexture = null;
|
||||
|
||||
DestroyImmediate(cubemap);
|
||||
}
|
||||
|
||||
if (renderCamObj != null)
|
||||
DestroyImmediate(renderCamObj);
|
||||
|
||||
if (mirrorTexture != null)
|
||||
DestroyImmediate(mirrorTexture);
|
||||
|
||||
if (renderTexture != null)
|
||||
DestroyImmediate(renderTexture);
|
||||
}
|
||||
// Creation
|
||||
private void CreateRenderCamera()
|
||||
{
|
||||
if (renderCamObj == null)
|
||||
{
|
||||
renderCamObj = new GameObject();
|
||||
renderCamObj.name = "Reflection Probe Cam";
|
||||
renderCamObj.hideFlags = HideFlags.HideAndDontSave;
|
||||
renderCam = renderCamObj.AddComponent<Camera>();
|
||||
renderCam.gameObject.SetActive(true);
|
||||
renderCam.cameraType = CameraType.Reflection;
|
||||
renderCam.fieldOfView = 90;
|
||||
renderCam.farClipPlane = myProbe.farClipPlane;
|
||||
renderCam.nearClipPlane = myProbe.nearClipPlane;
|
||||
renderCam.clearFlags = (CameraClearFlags)myProbe.clearFlags;
|
||||
renderCam.backgroundColor = myProbe.backgroundColor;
|
||||
renderCam.allowHDR = myProbe.hdr;
|
||||
renderCam.targetTexture = cubemap;
|
||||
renderCam.enabled = false;
|
||||
|
||||
#if VEGETATION_STUDIO_PRO
|
||||
// VegetationStudioManager.Instance.AddCamera(renderCam);
|
||||
#endif
|
||||
|
||||
#if !ENVIRO_HDRP
|
||||
if (EnviroManager.instance != null)
|
||||
{
|
||||
enviroRenderer = renderCamObj.AddComponent<EnviroRenderer>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
private void UpdateCameraSettings()
|
||||
{
|
||||
if (renderCam != null)
|
||||
{
|
||||
renderCam.cullingMask = myProbe.cullingMask;
|
||||
#if !ENVIRO_HDRP
|
||||
if (EnviroManager.instance != null)
|
||||
{
|
||||
//Update Quality
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
private Camera CreateBakingCamera()
|
||||
{
|
||||
GameObject tempCam = new GameObject();
|
||||
tempCam.name = "Reflection Probe Cam";
|
||||
Camera cam = tempCam.AddComponent<Camera>();
|
||||
cam.enabled = false;
|
||||
cam.gameObject.SetActive(true);
|
||||
cam.cameraType = CameraType.Reflection;
|
||||
cam.fieldOfView = 90;
|
||||
cam.farClipPlane = myProbe.farClipPlane;
|
||||
cam.nearClipPlane = myProbe.nearClipPlane;
|
||||
cam.cullingMask = myProbe.cullingMask;
|
||||
cam.clearFlags = (CameraClearFlags)myProbe.clearFlags;
|
||||
cam.backgroundColor = myProbe.backgroundColor;
|
||||
cam.allowHDR = myProbe.hdr;
|
||||
cam.targetTexture = cubemap;
|
||||
#if !ENVIRO_HDRP
|
||||
if (EnviroManager.instance != null)
|
||||
{
|
||||
enviroRenderer = renderCamObj.AddComponent<EnviroRenderer>();
|
||||
}
|
||||
#endif
|
||||
tempCam.hideFlags = HideFlags.HideAndDontSave;
|
||||
return cam;
|
||||
}
|
||||
private void CreateCubemap()
|
||||
{
|
||||
if (cubemap != null && myProbe.resolution == currentRes)
|
||||
return;
|
||||
|
||||
if (cubemap != null)
|
||||
{
|
||||
cubemap.Release();
|
||||
DestroyImmediate(cubemap);
|
||||
}
|
||||
|
||||
if (finalCubemap != null)
|
||||
{
|
||||
finalCubemap.Release();
|
||||
DestroyImmediate(finalCubemap);
|
||||
}
|
||||
|
||||
|
||||
int resolution = myProbe.resolution;
|
||||
|
||||
currentRes = resolution;
|
||||
RenderTextureFormat format = myProbe.hdr ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
|
||||
|
||||
cubemap = new RenderTexture(resolution, resolution, 16, format, RenderTextureReadWrite.Linear);
|
||||
cubemap.dimension = TextureDimension.Cube;
|
||||
cubemap.useMipMap = true;
|
||||
cubemap.autoGenerateMips = false;
|
||||
cubemap.name = "Enviro Reflection Temp Cubemap";
|
||||
cubemap.filterMode = FilterMode.Trilinear;
|
||||
cubemap.Create();
|
||||
|
||||
finalCubemap = new RenderTexture(resolution, resolution, 16, format, RenderTextureReadWrite.Linear);
|
||||
finalCubemap.dimension = TextureDimension.Cube;
|
||||
finalCubemap.useMipMap = true;
|
||||
finalCubemap.autoGenerateMips = false;
|
||||
finalCubemap.name = "Enviro Reflection Final Cubemap";
|
||||
finalCubemap.filterMode = FilterMode.Trilinear;
|
||||
finalCubemap.Create();
|
||||
}
|
||||
//Create the textures
|
||||
private void CreateTexturesAndMaterial()
|
||||
{
|
||||
if (mirror == null)
|
||||
mirror = new Material(Shader.Find("Hidden/Enviro/ReflectionProbe"));
|
||||
|
||||
if (convolutionMat == null)
|
||||
convolutionMat = new Material(Shader.Find("Hidden/EnviroCubemapBlur"));
|
||||
|
||||
int resolution = myProbe.resolution;
|
||||
|
||||
RenderTextureFormat format = myProbe.hdr ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
|
||||
|
||||
if (mirrorTexture == null || mirrorTexture.width != resolution || mirrorTexture.height != resolution)
|
||||
{
|
||||
if (mirrorTexture != null)
|
||||
DestroyImmediate(mirrorTexture);
|
||||
|
||||
mirrorTexture = new RenderTexture(resolution, resolution, 16, format, RenderTextureReadWrite.Linear);
|
||||
mirrorTexture.useMipMap = true;
|
||||
mirrorTexture.autoGenerateMips = false;
|
||||
mirrorTexture.name = "Enviro Reflection Mirror Texture";
|
||||
mirrorTexture.Create();
|
||||
}
|
||||
|
||||
if (renderTexture == null || renderTexture.width != resolution || renderTexture.height != resolution)
|
||||
{
|
||||
if (renderTexture != null)
|
||||
DestroyImmediate(renderTexture);
|
||||
|
||||
renderTexture = new RenderTexture(resolution, resolution, 16, format, RenderTextureReadWrite.Linear);
|
||||
renderTexture.useMipMap = true;
|
||||
renderTexture.autoGenerateMips = false;
|
||||
renderTexture.name = "Enviro Reflection Target Texture";
|
||||
renderTexture.Create();
|
||||
}
|
||||
}
|
||||
// Refresh Methods
|
||||
public void RefreshReflection(bool timeSlice = false)
|
||||
{
|
||||
#if ENVIRO_HDRP
|
||||
if (customRendering)
|
||||
{
|
||||
if (refreshing != null)
|
||||
return;
|
||||
|
||||
CreateTexturesAndMaterial();
|
||||
|
||||
if (renderCam == null)
|
||||
CreateRenderCamera();
|
||||
|
||||
UpdateCameraSettings();
|
||||
|
||||
renderCam.transform.position = transform.position;
|
||||
renderCam.targetTexture = renderTexture;
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
if (!timeSlice)
|
||||
refreshing = StartCoroutine(RefreshInstant(renderTexture, mirrorTexture));
|
||||
else
|
||||
refreshing = StartCoroutine(RefreshOvertime(renderTexture, mirrorTexture));
|
||||
}
|
||||
else
|
||||
{
|
||||
refreshing = StartCoroutine(RefreshInstant(renderTexture, mirrorTexture));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if(hdprobe != null)
|
||||
hdprobe.RequestRenderNextUpdate();
|
||||
}
|
||||
#else
|
||||
if (customRendering)
|
||||
{
|
||||
if (refreshing != null)
|
||||
return;
|
||||
|
||||
CreateTexturesAndMaterial();
|
||||
|
||||
if (renderCam == null)
|
||||
CreateRenderCamera();
|
||||
|
||||
UpdateCameraSettings();
|
||||
|
||||
renderCam.transform.position = transform.position;
|
||||
renderCam.targetTexture = renderTexture;
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
if (!timeSlice)
|
||||
refreshing = StartCoroutine(RefreshInstant(renderTexture, mirrorTexture));
|
||||
else
|
||||
refreshing = StartCoroutine(RefreshOvertime(renderTexture, mirrorTexture));
|
||||
}
|
||||
else
|
||||
{
|
||||
refreshing = StartCoroutine(RefreshInstant(renderTexture, mirrorTexture));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
renderId = myProbe.RenderProbe();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
IEnumerator RefreshFirstTime()
|
||||
{
|
||||
yield return null;
|
||||
RefreshReflection(false);
|
||||
RefreshReflection(false);
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator RefreshUnity()
|
||||
{
|
||||
yield return null;
|
||||
renderId = myProbe.RenderProbe();
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator RefreshInstant(RenderTexture renderTex, RenderTexture mirrorTex)
|
||||
{
|
||||
CreateCubemap();
|
||||
|
||||
yield return null;
|
||||
|
||||
for (int face = 0; face < 6; face++)
|
||||
{
|
||||
renderCam.transform.rotation = orientations[face];
|
||||
renderCam.Render();
|
||||
|
||||
if(mirrorTex != null)
|
||||
{
|
||||
Graphics.Blit(renderTex, mirrorTex, mirror);
|
||||
Graphics.CopyTexture(mirrorTex, 0, 0, cubemap, face, 0);
|
||||
}
|
||||
}
|
||||
|
||||
ConvolutionCubemap();
|
||||
#if ENVIRO_HDRP
|
||||
if (hdprobe != null)
|
||||
hdprobe.SetTexture(ProbeSettings.Mode.Custom, finalCubemap);
|
||||
#else
|
||||
myProbe.customBakedTexture = finalCubemap;
|
||||
#endif
|
||||
refreshing = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Reflections with Time Slicing
|
||||
/// </summary>
|
||||
public IEnumerator RefreshOvertime(RenderTexture renderTex, RenderTexture mirrorTex)
|
||||
{
|
||||
CreateCubemap();
|
||||
|
||||
for (int face = 0; face < 6; face++)
|
||||
{
|
||||
yield return null;
|
||||
renderCam.transform.rotation = orientations[face];
|
||||
renderCam.Render();
|
||||
|
||||
if(mirrorTex != null)
|
||||
{
|
||||
Graphics.Blit(renderTex, mirrorTex, mirror);
|
||||
Graphics.CopyTexture(mirrorTex, 0, 0, cubemap, face, 0);
|
||||
}
|
||||
//ClearTextures();
|
||||
}
|
||||
|
||||
ConvolutionCubemap();
|
||||
#if ENVIRO_HDRP
|
||||
if (hdprobe != null)
|
||||
hdprobe.SetTexture(ProbeSettings.Mode.Custom, finalCubemap);
|
||||
#else
|
||||
myProbe.customBakedTexture = finalCubemap;
|
||||
#endif
|
||||
refreshing = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bakes one face per time into a render texture
|
||||
/// </summary>
|
||||
/// <param name="face"></param>
|
||||
/// <param name="res"></param>
|
||||
/// <returns></returns>
|
||||
public RenderTexture BakeCubemapFace(int face, int res)
|
||||
{
|
||||
if (bakeMat == null)
|
||||
bakeMat = new Material(Shader.Find("Hidden/Enviro/BakeCubemap"));
|
||||
|
||||
if (bakingCam == null)
|
||||
bakingCam = CreateBakingCamera();
|
||||
|
||||
bakingCam.transform.rotation = orientations[face];
|
||||
RenderTexture temp = RenderTexture.GetTemporary(res, res, 0, RenderTextureFormat.ARGBFloat);
|
||||
bakingCam.targetTexture = temp;
|
||||
bakingCam.Render();
|
||||
RenderTexture tex = new RenderTexture(res, res, 0, RenderTextureFormat.ARGBFloat);
|
||||
Graphics.Blit(temp, tex, bakeMat);
|
||||
RenderTexture.ReleaseTemporary(temp);
|
||||
return tex;
|
||||
}
|
||||
|
||||
private void ClearTextures()
|
||||
{
|
||||
RenderTexture rt = RenderTexture.active;
|
||||
RenderTexture.active = renderTexture;
|
||||
GL.Clear(true, true, Color.clear);
|
||||
RenderTexture.active = mirrorTexture;
|
||||
GL.Clear(true, true, Color.clear);
|
||||
RenderTexture.active = rt;
|
||||
}
|
||||
|
||||
|
||||
//This is not a proper convolution and very hacky to get anywhere near of unity realtime reflection probe mip convolution.
|
||||
private void ConvolutionCubemap()
|
||||
{
|
||||
int mipCount = 7;
|
||||
|
||||
GL.PushMatrix();
|
||||
GL.LoadOrtho();
|
||||
|
||||
cubemap.GenerateMips();
|
||||
|
||||
float texel = 1f;
|
||||
switch(finalCubemap.width)
|
||||
{
|
||||
|
||||
case 16:
|
||||
texel = 1f;
|
||||
break;
|
||||
|
||||
case 32:
|
||||
texel = 1f;
|
||||
break;
|
||||
|
||||
case 64:
|
||||
texel = 2f;
|
||||
break;
|
||||
|
||||
case 128:
|
||||
texel = 4f;
|
||||
break;
|
||||
|
||||
case 256:
|
||||
texel = 8f;
|
||||
break;
|
||||
|
||||
case 512:
|
||||
texel = 14f;
|
||||
break;
|
||||
|
||||
case 1024:
|
||||
texel = 30f;
|
||||
break;
|
||||
|
||||
case 2048:
|
||||
texel = 60f;
|
||||
break;
|
||||
}
|
||||
|
||||
float res = finalCubemap.width;
|
||||
|
||||
for (int mip = 0; mip < mipCount + 1; mip++)
|
||||
{
|
||||
//Copy each face
|
||||
Graphics.CopyTexture(cubemap, 0, mip, finalCubemap, 0, mip);
|
||||
Graphics.CopyTexture(cubemap, 1, mip, finalCubemap, 1, mip);
|
||||
Graphics.CopyTexture(cubemap, 2, mip, finalCubemap, 2, mip);
|
||||
Graphics.CopyTexture(cubemap, 3, mip, finalCubemap, 3, mip);
|
||||
Graphics.CopyTexture(cubemap, 4, mip, finalCubemap, 4, mip);
|
||||
Graphics.CopyTexture(cubemap, 5, mip, finalCubemap, 5, mip);
|
||||
|
||||
int dstMip = mip + 1;
|
||||
|
||||
if (dstMip == mipCount)
|
||||
break;
|
||||
|
||||
float texelSize = (texel * dstMip) / res;
|
||||
|
||||
convolutionMat.SetTexture("_MainTex", finalCubemap);
|
||||
convolutionMat.SetFloat("_Texel", texelSize);
|
||||
convolutionMat.SetFloat("_Level", mip);
|
||||
convolutionMat.SetPass(0);
|
||||
|
||||
res *= 0.75f;
|
||||
|
||||
// Positive X
|
||||
Graphics.SetRenderTarget(cubemap, dstMip, CubemapFace.PositiveX);
|
||||
GL.Begin(GL.QUADS);
|
||||
GL.TexCoord3(1, 1, 1);
|
||||
GL.Vertex3(0, 0, 1);
|
||||
GL.TexCoord3(1, -1, 1);
|
||||
GL.Vertex3(0, 1, 1);
|
||||
GL.TexCoord3(1, -1, -1);
|
||||
GL.Vertex3(1, 1, 1);
|
||||
GL.TexCoord3(1, 1, -1);
|
||||
GL.Vertex3(1, 0, 1);
|
||||
GL.End();
|
||||
|
||||
// Negative X
|
||||
Graphics.SetRenderTarget(cubemap, dstMip, CubemapFace.NegativeX);
|
||||
GL.Begin(GL.QUADS);
|
||||
GL.TexCoord3(-1, 1, -1);
|
||||
GL.Vertex3(0, 0, 1);
|
||||
GL.TexCoord3(-1, -1, -1);
|
||||
GL.Vertex3(0, 1, 1);
|
||||
GL.TexCoord3(-1, -1, 1);
|
||||
GL.Vertex3(1, 1, 1);
|
||||
GL.TexCoord3(-1, 1, 1);
|
||||
GL.Vertex3(1, 0, 1);
|
||||
GL.End();
|
||||
|
||||
// Positive Y
|
||||
Graphics.SetRenderTarget(cubemap, dstMip, CubemapFace.PositiveY);
|
||||
GL.Begin(GL.QUADS);
|
||||
GL.TexCoord3(-1, 1, -1);
|
||||
GL.Vertex3(0, 0, 1);
|
||||
GL.TexCoord3(-1, 1, 1);
|
||||
GL.Vertex3(0, 1, 1);
|
||||
GL.TexCoord3(1, 1, 1);
|
||||
GL.Vertex3(1, 1, 1);
|
||||
GL.TexCoord3(1, 1, -1);
|
||||
GL.Vertex3(1, 0, 1);
|
||||
GL.End();
|
||||
|
||||
// Negative Y
|
||||
Graphics.SetRenderTarget(cubemap, dstMip, CubemapFace.NegativeY);
|
||||
GL.Begin(GL.QUADS);
|
||||
GL.TexCoord3(-1, -1, 1);
|
||||
GL.Vertex3(0, 0, 1);
|
||||
GL.TexCoord3(-1, -1, -1);
|
||||
GL.Vertex3(0, 1, 1);
|
||||
GL.TexCoord3(1, -1, -1);
|
||||
GL.Vertex3(1, 1, 1);
|
||||
GL.TexCoord3(1, -1, 1);
|
||||
GL.Vertex3(1, 0, 1);
|
||||
GL.End();
|
||||
|
||||
// Positive Z
|
||||
Graphics.SetRenderTarget(cubemap, dstMip, CubemapFace.PositiveZ);
|
||||
GL.Begin(GL.QUADS);
|
||||
GL.TexCoord3(-1, 1, 1);
|
||||
GL.Vertex3(0, 0, 1);
|
||||
GL.TexCoord3(-1, -1, 1);
|
||||
GL.Vertex3(0, 1, 1);
|
||||
GL.TexCoord3(1, -1, 1);
|
||||
GL.Vertex3(1, 1, 1);
|
||||
GL.TexCoord3(1, 1, 1);
|
||||
GL.Vertex3(1, 0, 1);
|
||||
GL.End();
|
||||
|
||||
// Negative Z
|
||||
Graphics.SetRenderTarget(cubemap, dstMip, CubemapFace.NegativeZ);
|
||||
GL.Begin(GL.QUADS);
|
||||
GL.TexCoord3(1, 1, -1);
|
||||
GL.Vertex3(0, 0, 1);
|
||||
GL.TexCoord3(1, -1, -1);
|
||||
GL.Vertex3(0, 1, 1);
|
||||
GL.TexCoord3(-1, -1, -1);
|
||||
GL.Vertex3(1, 1, 1);
|
||||
GL.TexCoord3(-1, 1, -1);
|
||||
GL.Vertex3(1, 0, 1);
|
||||
GL.End();
|
||||
}
|
||||
|
||||
GL.PopMatrix();
|
||||
|
||||
}
|
||||
private void UpdateStandaloneReflection()
|
||||
{
|
||||
if ((EnviroManager.instance.Time.GetDateInHours() > lastRelfectionUpdate + reflectionsUpdateTreshhold ||EnviroManager.instance.Time.GetDateInHours() < lastRelfectionUpdate - reflectionsUpdateTreshhold) && updateReflectionOnGameTime)
|
||||
{
|
||||
lastRelfectionUpdate = EnviroManager.instance.Time.GetDateInHours();
|
||||
RefreshReflection(!useTimeSlicing);
|
||||
}
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (currentMode != customRendering)
|
||||
{
|
||||
currentMode = customRendering;
|
||||
|
||||
if (customRendering)
|
||||
{
|
||||
OnEnable();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnEnable();
|
||||
Cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
if (EnviroManager.instance != null && standalone)
|
||||
{
|
||||
UpdateStandaloneReflection();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 766b1caed0279ea4281500fc502a2853
|
||||
timeCreated: 1558916543
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Reflections/EnviroReflectionProbe.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,407 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
[Serializable]
|
||||
public class EnviroReflections
|
||||
{
|
||||
public enum GlobalReflectionResolution
|
||||
{
|
||||
R16,
|
||||
R32,
|
||||
R64,
|
||||
R128,
|
||||
R256,
|
||||
R512,
|
||||
R1024,
|
||||
R2048
|
||||
}
|
||||
|
||||
public bool globalReflections = true;
|
||||
[Tooltip("Set if enviro reflection probe should use custom rendering setup. For example to include post effectsin birp.")]
|
||||
public bool customRendering = true;
|
||||
[Tooltip("Set to use custom timeslicing when rendered in custom mode.")]
|
||||
public bool customRenderingTimeSlicing = true;
|
||||
|
||||
[Tooltip("Set if enviro reflection probe should update faces individual on different frames.")]
|
||||
public ReflectionProbeTimeSlicingMode globalReflectionTimeSlicingMode = ReflectionProbeTimeSlicingMode.IndividualFaces;
|
||||
[Tooltip("Enable/disable enviro reflection probe updates based on gametime changes..")]
|
||||
public bool globalReflectionsUpdateOnGameTime = true;
|
||||
[Tooltip("Enable/disable enviro reflection probe updates based on transform position changes..")]
|
||||
public bool globalReflectionsUpdateOnPosition = true;
|
||||
[Tooltip("Reflection probe intensity.")]
|
||||
[Range(0f, 2f)]
|
||||
public float globalReflectionsIntensity = 1.0f;
|
||||
[Tooltip("Reflection probe update rate based on game time.")]
|
||||
public float globalReflectionsTimeTreshold = 0.025f;
|
||||
[Tooltip("Reflection probe update rate based on camera position.")]
|
||||
public float globalReflectionsPositionTreshold = 0.5f;
|
||||
[Tooltip("Reflection probe scale. Increase that one to increase the area where reflection probe will influence your scene.")]
|
||||
[Range(10f, 10000f)]
|
||||
public float globalReflectionsScale = 10000f;
|
||||
[Tooltip("Reflection probe resolution.")]
|
||||
public GlobalReflectionResolution globalReflectionResolution = GlobalReflectionResolution.R256;
|
||||
[Tooltip("Reflection probe rendered Layers.")]
|
||||
public LayerMask globalReflectionLayers;
|
||||
[Tooltip("Enable this option to update the default reflection with global reflection probes cubemap. This can be needed for material that might not support direct reflection probes. (Instanced Indirect Rendering)")]
|
||||
public bool updateDefaultEnvironmentReflections = true;
|
||||
[Tooltip("Reflection cubemap used for default scene sky reflections in < Unity 2022.1 versions.")]
|
||||
public Cubemap defaultSkyReflectionTex;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[ExecuteInEditMode]
|
||||
public class EnviroReflectionsModule : EnviroModule
|
||||
{
|
||||
public Enviro.EnviroReflections Settings;
|
||||
public EnviroReflectionsModule preset;
|
||||
|
||||
// Inspector
|
||||
public bool showReflectionControls;
|
||||
|
||||
public float lastReflectionUpdate;
|
||||
public Vector3 lastReflectionUpdatePos;
|
||||
|
||||
private Coroutine renderReflectionCoroutine;
|
||||
private Coroutine waitForProbeCoroutine;
|
||||
private Coroutine copyDefaultReflectionCoroutine;
|
||||
|
||||
public override void Enable ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
Setup();
|
||||
|
||||
// Update global reflections once on enable.
|
||||
if(EnviroManager.instance.Objects.globalReflectionProbe != null)
|
||||
EnviroManager.instance.StartCoroutine(WaitToRefreshReflection());
|
||||
}
|
||||
|
||||
public override void Disable ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
private void Cleanup()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance.Objects.globalReflectionProbe != null)
|
||||
DestroyImmediate(EnviroManager.instance.Objects.globalReflectionProbe.gameObject);
|
||||
}
|
||||
|
||||
// Unity warns with "Attempting to update a disabled Reflection Probe" even though the probe is enabled.
|
||||
// We have to wait a frame before interacting with reflection probes to allow Unity time to do any
|
||||
// setup in its internal OnEnable(). Otherwise, we will receive a warning:
|
||||
// "Attempting to update a disabled Reflection Probe. Action will be ignored."
|
||||
private IEnumerator WaitToRefreshReflection()
|
||||
{
|
||||
yield return null;
|
||||
RenderGlobalReflectionProbe(true, false);
|
||||
UpdateDefaultReflectionTextureMode ();
|
||||
}
|
||||
|
||||
private void Setup()
|
||||
{
|
||||
if(EnviroManager.instance.Objects.globalReflectionProbe == null)
|
||||
{
|
||||
GameObject newReflectionProbe = new GameObject();
|
||||
newReflectionProbe.name = "Global Reflection Probe";
|
||||
newReflectionProbe.transform.SetParent(EnviroManager.instance.transform);
|
||||
newReflectionProbe.transform.localPosition = Vector3.zero;
|
||||
EnviroManager.instance.Objects.globalReflectionProbe = newReflectionProbe.AddComponent<EnviroReflectionProbe>();
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
if(EnviroManager.instance == null)
|
||||
return;
|
||||
|
||||
if(EnviroManager.instance.Objects.globalReflectionProbe != null)
|
||||
UpdateReflection();
|
||||
}
|
||||
|
||||
private void UpdateReflection()
|
||||
{
|
||||
if(!Settings.globalReflections)
|
||||
{
|
||||
EnviroManager.instance.Objects.globalReflectionProbe.myProbe.enabled = false;
|
||||
UpdateDefaultReflectionTextureMode ();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
EnviroManager.instance.Objects.globalReflectionProbe.myProbe.enabled = true;
|
||||
}
|
||||
|
||||
EnviroReflectionProbe probe = EnviroManager.instance.Objects.globalReflectionProbe;
|
||||
|
||||
SetupProbeSettings(probe);
|
||||
|
||||
if(EnviroManager.instance.Time != null)
|
||||
{
|
||||
if ((lastReflectionUpdate < EnviroManager.instance.Time.Settings.timeOfDay || lastReflectionUpdate > EnviroManager.instance.Time.Settings.timeOfDay + (Settings.globalReflectionsTimeTreshold + 0.01f)) && Settings.globalReflectionsUpdateOnGameTime)
|
||||
{
|
||||
RenderGlobalReflectionProbe(false,Settings.customRenderingTimeSlicing);
|
||||
lastReflectionUpdate = EnviroManager.instance.Time.Settings.timeOfDay + Settings.globalReflectionsTimeTreshold;
|
||||
}
|
||||
}
|
||||
|
||||
if ((probe.transform.position.magnitude > lastReflectionUpdatePos.magnitude + Settings.globalReflectionsPositionTreshold || probe.transform.position.magnitude < lastReflectionUpdatePos.magnitude - Settings.globalReflectionsPositionTreshold) && Settings.globalReflectionsUpdateOnPosition)
|
||||
{
|
||||
RenderGlobalReflectionProbe(false,Settings.customRenderingTimeSlicing);
|
||||
lastReflectionUpdatePos = probe.transform.position;
|
||||
}
|
||||
|
||||
UpdateDefaultReflectionTextureMode ();
|
||||
}
|
||||
|
||||
public void RenderGlobalReflectionProbe(bool forced = false, bool timeslice = false)
|
||||
{
|
||||
EnviroReflectionProbe probe = EnviroManager.instance.Objects.globalReflectionProbe;
|
||||
|
||||
if (probe == null)
|
||||
return;
|
||||
|
||||
if(renderReflectionCoroutine != null)
|
||||
{
|
||||
EnviroManager.instance.StopCoroutine(renderReflectionCoroutine);
|
||||
renderReflectionCoroutine = null;
|
||||
}
|
||||
|
||||
#if !ENVIRO_HDRP
|
||||
renderReflectionCoroutine = EnviroManager.instance.StartCoroutine(RenderGlobalReflectionProbeTimed(probe,timeslice));
|
||||
|
||||
if(Settings.updateDefaultEnvironmentReflections)
|
||||
{
|
||||
#if UNITY_2022_1_OR_NEWER
|
||||
// We don't need to copy the texture to a cubemap anmyore
|
||||
#else
|
||||
// Prevent multiple coroutines from running at the same time
|
||||
if (copyDefaultReflectionCoroutine != null)
|
||||
{
|
||||
EnviroManager.instance.StopCoroutine(copyDefaultReflectionCoroutine);
|
||||
copyDefaultReflectionCoroutine = null;
|
||||
}
|
||||
|
||||
if(Settings.customRendering)
|
||||
copyDefaultReflectionCoroutine = EnviroManager.instance.StartCoroutine(CopyDefaultReflectionCustom(probe, timeslice));
|
||||
else
|
||||
CopyDefaultReflectionUnity(probe);
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
renderReflectionCoroutine = EnviroManager.instance.StartCoroutine(RenderGlobalReflectionProbeTimed(probe,timeslice));
|
||||
#endif
|
||||
}
|
||||
|
||||
//Copy reflection probe to cubemap and assign as default reflections.
|
||||
private void CopyDefaultReflectionCubemap (EnviroReflectionProbe probe)
|
||||
{
|
||||
if(Settings.defaultSkyReflectionTex == null || Settings.defaultSkyReflectionTex.height != probe.myProbe.texture.height || Settings.defaultSkyReflectionTex.width != probe.myProbe.texture.width)
|
||||
{
|
||||
if(Settings.defaultSkyReflectionTex != null)
|
||||
DestroyImmediate(Settings.defaultSkyReflectionTex);
|
||||
|
||||
Settings.defaultSkyReflectionTex = new Cubemap(probe.myProbe.resolution, probe.myProbe.hdr ? TextureFormat.RGBAHalf : TextureFormat.RGBA32, true);
|
||||
Settings.defaultSkyReflectionTex.name = "Enviro Default Sky Reflection";
|
||||
}
|
||||
|
||||
if(probe.myProbe.texture != null)
|
||||
Graphics.CopyTexture(probe.myProbe.texture, Settings.defaultSkyReflectionTex as Texture);
|
||||
}
|
||||
|
||||
public void UpdateDefaultReflectionTextureMode ()
|
||||
{
|
||||
if(Settings.updateDefaultEnvironmentReflections && Settings.globalReflections)
|
||||
{
|
||||
RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
|
||||
|
||||
#if UNITY_2022_1_OR_NEWER
|
||||
RenderSettings.customReflectionTexture = EnviroManager.instance.Objects.globalReflectionProbe.myProbe.texture;
|
||||
#else
|
||||
if(Settings.defaultSkyReflectionTex != null)
|
||||
RenderSettings.customReflection = Settings.defaultSkyReflectionTex;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Skybox;
|
||||
}
|
||||
}
|
||||
|
||||
//Update all probe settings.
|
||||
private void SetupProbeSettings(EnviroReflectionProbe probe)
|
||||
{
|
||||
int res = 128;
|
||||
|
||||
switch (Settings.globalReflectionResolution)
|
||||
{
|
||||
case EnviroReflections.GlobalReflectionResolution.R16:
|
||||
res = 16;
|
||||
break;
|
||||
case EnviroReflections.GlobalReflectionResolution.R32:
|
||||
res = 32;
|
||||
break;
|
||||
case EnviroReflections.GlobalReflectionResolution.R64:
|
||||
res = 64;
|
||||
break;
|
||||
case EnviroReflections.GlobalReflectionResolution.R128:
|
||||
res = 128;
|
||||
break;
|
||||
case EnviroReflections.GlobalReflectionResolution.R256:
|
||||
res = 256;
|
||||
break;
|
||||
case EnviroReflections.GlobalReflectionResolution.R512:
|
||||
res = 512;
|
||||
break;
|
||||
case EnviroReflections.GlobalReflectionResolution.R1024:
|
||||
res = 1024;
|
||||
break;
|
||||
case EnviroReflections.GlobalReflectionResolution.R2048:
|
||||
res = 2048;
|
||||
break;
|
||||
}
|
||||
#if !ENVIRO_HDRP
|
||||
probe.myProbe.cullingMask = Settings.globalReflectionLayers;
|
||||
probe.myProbe.intensity = Settings.globalReflectionsIntensity;
|
||||
probe.myProbe.size = new Vector3 (Settings.globalReflectionsScale,Settings.globalReflectionsScale,Settings.globalReflectionsScale);
|
||||
probe.myProbe.resolution = res;
|
||||
#if ENVIRO_URP
|
||||
probe.customRendering = false;
|
||||
probe.myProbe.timeSlicingMode = Settings.globalReflectionTimeSlicingMode;
|
||||
#else
|
||||
probe.customRendering = Settings.customRendering;
|
||||
probe.useTimeSlicing = Settings.customRenderingTimeSlicing;
|
||||
probe.myProbe.timeSlicingMode = Settings.globalReflectionTimeSlicingMode;
|
||||
#endif
|
||||
RenderSettings.reflectionIntensity = Settings.globalReflectionsIntensity;
|
||||
#else
|
||||
probe.customRendering = false;
|
||||
probe.myProbe.resolution = res;
|
||||
|
||||
if(probe.hdprobe != null)
|
||||
{
|
||||
probe.hdprobe.settingsRaw.cameraSettings.culling.cullingMask = Settings.globalReflectionLayers;
|
||||
probe.hdprobe.settingsRaw.influence.boxSize = new Vector3 (Settings.globalReflectionsScale,Settings.globalReflectionsScale,Settings.globalReflectionsScale);
|
||||
probe.hdprobe.settingsRaw.influence.sphereRadius = Settings.globalReflectionsScale;
|
||||
probe.hdprobe.settingsRaw.lighting.multiplier = Settings.globalReflectionsIntensity;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private IEnumerator CopyDefaultReflectionCustom(EnviroReflectionProbe probe, bool timeslice)
|
||||
{
|
||||
if (timeslice)
|
||||
{
|
||||
// Wait for seven frames so probe finished rendering
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
CopyDefaultReflectionCubemap(probe);
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return null;
|
||||
yield return null;
|
||||
CopyDefaultReflectionCubemap(probe);
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyDefaultReflectionUnity(EnviroReflectionProbe probe)
|
||||
{
|
||||
if(probe.renderId == -1 || probe.myProbe.IsFinishedRendering(probe.renderId))
|
||||
{
|
||||
CopyDefaultReflectionCubemap(probe);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (waitForProbeCoroutine != null) {
|
||||
EnviroManager.instance.StopCoroutine(waitForProbeCoroutine);
|
||||
waitForProbeCoroutine = null;
|
||||
}
|
||||
waitForProbeCoroutine = EnviroManager.instance.StartCoroutine(WaitForUnityProbe(probe));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator WaitForUnityProbe(EnviroReflectionProbe probe)
|
||||
{
|
||||
yield return null;
|
||||
CopyDefaultReflectionUnity(probe);
|
||||
}
|
||||
|
||||
private IEnumerator RenderGlobalReflectionProbeTimed (EnviroReflectionProbe probe, bool timeslice)
|
||||
{
|
||||
#if ENVIRO_HDRP
|
||||
EnviroManager.instance.Lighting.UpdateDirectLightingHDRP ();
|
||||
EnviroManager.instance.Lighting.UpdateAmbientLightingHDRP();
|
||||
yield return null;
|
||||
probe.RefreshReflection(timeslice);
|
||||
yield return null;
|
||||
EnviroManager.instance.Lighting.UpdateExposureHDRP ();
|
||||
#else
|
||||
if(EnviroManager.instance.Lighting != null)
|
||||
{
|
||||
//Force a lighting update before rendering the probe as it might has not updated yet.
|
||||
EnviroManager.instance.Lighting.UpdateDirectLighting ();
|
||||
EnviroManager.instance.Lighting.UpdateAmbientLighting(true);
|
||||
yield return null;
|
||||
probe.RefreshReflection(timeslice);
|
||||
}
|
||||
else
|
||||
{
|
||||
probe.RefreshReflection(timeslice);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
Settings = JsonUtility.FromJson<Enviro.EnviroReflections>(JsonUtility.ToJson(preset.Settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroReflectionsModule t = ScriptableObject.CreateInstance<EnviroReflectionsModule>();
|
||||
t.name = "Reflections Module";
|
||||
t.Settings = JsonUtility.FromJson<Enviro.EnviroReflections>(JsonUtility.ToJson(Settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SaveModuleValues (EnviroReflectionsModule module)
|
||||
{
|
||||
module.Settings = JsonUtility.FromJson<Enviro.EnviroReflections>(JsonUtility.ToJson(Settings));
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 153c2e7862a6cc74c80438e6d8e45aab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Reflections/EnviroReflectionsModule.cs
|
||||
uploadId: 660896
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user