add weather and time
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user