升级6.4.升级水,升级天气
This commit is contained in:
@@ -14,22 +14,24 @@ namespace WaveHarmonic.Crest
|
||||
{
|
||||
[Tooltip("Whether to override the LOD bias.")]
|
||||
[@GenerateAPI]
|
||||
[@DecoratedField, SerializeField]
|
||||
[@InlineToggle]
|
||||
[@SerializeField]
|
||||
internal bool _OverrideLodBias;
|
||||
|
||||
[Tooltip("Overrides the LOD bias for meshes.\n\nHighest quality is infinity.")]
|
||||
[@Predicated(nameof(_OverrideLodBias))]
|
||||
[@Enable(nameof(_OverrideLodBias))]
|
||||
[@GenerateAPI]
|
||||
[@DecoratedField, SerializeField]
|
||||
internal float _LodBias;
|
||||
|
||||
[Tooltip("Whether to override the maximum LOD level.")]
|
||||
[@GenerateAPI]
|
||||
[@DecoratedField, SerializeField]
|
||||
[@InlineToggle]
|
||||
[@SerializeField]
|
||||
internal bool _OverrideMaximumLodLevel;
|
||||
|
||||
[Tooltip("Overrides the maximum LOD level.\n\nHighest quality is zero.")]
|
||||
[@Predicated(nameof(_OverrideMaximumLodLevel))]
|
||||
[@Enable(nameof(_OverrideMaximumLodLevel))]
|
||||
[@GenerateAPI]
|
||||
[@DecoratedField, SerializeField]
|
||||
internal int _MaximumLodLevel;
|
||||
@@ -37,11 +39,12 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
[Tooltip("Whether to override the terrain pixel error.")]
|
||||
[@GenerateAPI]
|
||||
[@DecoratedField, SerializeField]
|
||||
[@InlineToggle]
|
||||
[@SerializeField]
|
||||
internal bool _OverrideTerrainPixelError;
|
||||
|
||||
[Tooltip("Overrides the pixel error value for terrains.\n\nHighest quality is zero.")]
|
||||
[@Predicated(nameof(_OverrideTerrainPixelError))]
|
||||
[@Enable(nameof(_OverrideTerrainPixelError))]
|
||||
[@GenerateAPI]
|
||||
[@DecoratedField, SerializeField]
|
||||
internal float _TerrainPixelError;
|
||||
|
||||
@@ -5,11 +5,14 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Editor")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Integration.Gaia")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Shared.Editor")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Samples")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Samples.Boats")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Samples.Editor")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Samples.Examples")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Samples.Ripples")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Samples.Waterfall")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.Samples.Submarine")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.CPUQueries")]
|
||||
[assembly: InternalsVisibleTo("WaveHarmonic.Crest.CPUQueries.Editor")]
|
||||
|
||||
@@ -99,11 +99,22 @@ namespace WaveHarmonic.Crest
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
|
||||
abstract class Decorator : PropertyAttribute { }
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Order : Decorator
|
||||
{
|
||||
public enum Placement { Heading, Below, Above }
|
||||
public Order(string target, Placement placement = Placement.Heading) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Layer : Decorator { }
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Stripped : Decorator { }
|
||||
sealed class Stripped : Decorator
|
||||
{
|
||||
public enum Style { None, PlatformTab, }
|
||||
public Stripped(Style style = Style.None, bool indent = false) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Delayed : Decorator { }
|
||||
@@ -111,6 +122,18 @@ namespace WaveHarmonic.Crest
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Disabled : Decorator { }
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Required : Attribute { }
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class PlatformTabs : Attribute { }
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class CustomField : Attribute { }
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class CustomLabel : Attribute { }
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class AttachMaterialEditor : Attribute
|
||||
{
|
||||
@@ -153,25 +176,25 @@ namespace WaveHarmonic.Crest
|
||||
{
|
||||
[Flags]
|
||||
public enum Clamp { None = 0, Minimum = 1, Maximum = 2, Both = Minimum | Maximum }
|
||||
public Range(float minimum, float maximum, Clamp clamp = Clamp.Both, float scale = 1f, bool delayed = false, int step = 0, bool power = false) {}
|
||||
public Range(float minimum, float maximum, Clamp clamp = Clamp.Both, float scale = 1f, bool delayed = false, int step = 0, bool power = false) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Minimum : Decorator
|
||||
{
|
||||
public Minimum(float minimum) {}
|
||||
public Minimum(float minimum) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Maximum : Decorator
|
||||
{
|
||||
public Maximum(float maximum) {}
|
||||
public Maximum(float maximum) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class WarnIfAbove : Decorator
|
||||
{
|
||||
public WarnIfAbove(float maximum) {}
|
||||
public WarnIfAbove(float maximum) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
@@ -207,12 +230,47 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Predicated : Decorator
|
||||
sealed class Show : Decorator
|
||||
{
|
||||
public Predicated(Type type, string member, bool inverted = false, bool hide = false) { }
|
||||
public Predicated(Type type, bool inverted = false, bool hide = false) { }
|
||||
public Predicated(string property, bool inverted = false, object disableValue = null, bool hide = false) { }
|
||||
public Predicated(RenderPipeline rp, bool inverted = false, bool hide = false) { }
|
||||
public Show(Type type, string member, object value) { }
|
||||
public Show(Type type, string member) { }
|
||||
public Show(Type type) { }
|
||||
public Show(string property) { }
|
||||
public Show(string property, object value) { }
|
||||
public Show(RenderPipeline rp) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Hide : Decorator
|
||||
{
|
||||
public Hide(Type type, string member, object value) { }
|
||||
public Hide(Type type, string member) { }
|
||||
public Hide(Type type) { }
|
||||
public Hide(string property) { }
|
||||
public Hide(string property, object value) { }
|
||||
public Hide(RenderPipeline rp) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Enable : Decorator
|
||||
{
|
||||
public Enable(Type type, string member, object value) { }
|
||||
public Enable(Type type, string member) { }
|
||||
public Enable(Type type) { }
|
||||
public Enable(string property) { }
|
||||
public Enable(string property, object value) { }
|
||||
public Enable(RenderPipeline rp) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
sealed class Disable : Decorator
|
||||
{
|
||||
public Disable(Type type, string member, object value) { }
|
||||
public Disable(Type type, string member) { }
|
||||
public Disable(Type type) { }
|
||||
public Disable(string property) { }
|
||||
public Disable(string property, object value) { }
|
||||
public Disable(RenderPipeline rp) { }
|
||||
}
|
||||
|
||||
[Conditional(Symbols.k_UnityEditor)]
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using MonoBehaviour = WaveHarmonic.Crest.Internal.EditorBehaviour;
|
||||
#else
|
||||
using MonoBehaviour = UnityEngine.MonoBehaviour;
|
||||
@@ -14,7 +15,7 @@ namespace WaveHarmonic.Crest.Internal
|
||||
/// <summary>
|
||||
/// Implements logic to smooth out Unity's wrinkles.
|
||||
/// </summary>
|
||||
public abstract class CustomBehaviour : MonoBehaviour
|
||||
public abstract partial class CustomBehaviour : MonoBehaviour
|
||||
{
|
||||
bool _AfterStart;
|
||||
|
||||
@@ -71,11 +72,46 @@ namespace WaveHarmonic.Crest.Internal
|
||||
[InitializeOnEnterPlayMode]
|
||||
static void OnEnterPlayModeInEditor(EnterPlayModeOptions options)
|
||||
{
|
||||
foreach (var @object in FindObjectsByType<CustomBehaviour>(FindObjectsInactive.Include, FindObjectsSortMode.None))
|
||||
foreach (var @object in Helpers.FindObjectsByType<CustomBehaviour>(FindObjectsInactive.Include))
|
||||
{
|
||||
@object._AfterStart = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
partial class CustomBehaviour : ISerializationCallbackReceiver
|
||||
{
|
||||
#pragma warning disable 414
|
||||
[@SerializeField, @HideInInspector]
|
||||
private protected int _Version;
|
||||
#pragma warning restore 414
|
||||
|
||||
private protected virtual int Version => 0;
|
||||
|
||||
private protected CustomBehaviour()
|
||||
{
|
||||
// Sets the default version. Overriden by serialized field above.
|
||||
_Version = Version;
|
||||
}
|
||||
|
||||
private protected virtual void OnMigrate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||
{
|
||||
if (_Version < Version)
|
||||
{
|
||||
OnMigrate();
|
||||
_Version = Version;
|
||||
}
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements logic to smooth out Unity's wrinkles.
|
||||
/// </summary>
|
||||
public abstract partial class CustomScriptableObject : ScriptableObject
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
partial class CustomScriptableObject : ISerializationCallbackReceiver
|
||||
{
|
||||
#pragma warning disable 414
|
||||
[@SerializeField, @HideInInspector]
|
||||
private protected int _Version;
|
||||
#pragma warning restore 414
|
||||
|
||||
private protected virtual int Version => 0;
|
||||
|
||||
private protected CustomScriptableObject()
|
||||
{
|
||||
// Sets the default version. Overriden by serialized field above.
|
||||
_Version = Version;
|
||||
}
|
||||
|
||||
private protected virtual void OnMigrate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||
{
|
||||
if (_Version < Version)
|
||||
{
|
||||
OnMigrate();
|
||||
_Version = Version;
|
||||
}
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b6e085d4815447e4bb6dc81c0c8e2ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -98,7 +98,7 @@ namespace WaveHarmonic.Crest.Internal
|
||||
|
||||
// When singleton, destroy instance objects.
|
||||
if (enableInEditMode && attribute._Options.HasFlag(ExecuteDuringEditMode.Options.Singleton) &&
|
||||
FindObjectsByType(GetType(), FindObjectsSortMode.None).Length > 1)
|
||||
Helpers.FindObjectsByType(GetType()).Length > 1)
|
||||
{
|
||||
enableInEditMode = false;
|
||||
EditorApplication.update -= InternalDestroyNonSaveables;
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace WaveHarmonic.Crest.Internal
|
||||
|
||||
internal static void AfterScriptReload()
|
||||
{
|
||||
Instance = FindFirstObjectByType<T>();
|
||||
Instance = FindAnyObjectByType<T>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using UnityEngine.Rendering.HighDefinition;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
|
||||
#if !UNITY_2023_2_OR_NEWER
|
||||
#if !UNITY_6000_0_OR_NEWER
|
||||
using GraphicsFormatUsage = UnityEngine.Experimental.Rendering.FormatUsage;
|
||||
#endif
|
||||
|
||||
@@ -21,18 +21,6 @@ namespace WaveHarmonic.Crest
|
||||
/// </summary>
|
||||
static partial class Helpers
|
||||
{
|
||||
// Adapted from:
|
||||
// Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs
|
||||
#if UNITY_SWITCH || UNITY_ANDROID || UNITY_EMBEDDED_LINUX || UNITY_QNX
|
||||
internal const GraphicsFormat k_DepthStencilFormat = GraphicsFormat.D24_UNorm_S8_UInt;
|
||||
internal const int k_DepthBufferBits = 24;
|
||||
internal const DepthBits k_DepthBits = DepthBits.Depth24;
|
||||
#else
|
||||
internal const GraphicsFormat k_DepthStencilFormat = GraphicsFormat.D32_SFloat_S8_UInt;
|
||||
internal const int k_DepthBufferBits = 32;
|
||||
internal const DepthBits k_DepthBits = DepthBits.Depth32;
|
||||
#endif
|
||||
|
||||
public static class ShaderIDs
|
||||
{
|
||||
public static readonly int s_MainTexture = Shader.PropertyToID("_Utility_MainTexture");
|
||||
@@ -92,6 +80,24 @@ namespace WaveHarmonic.Crest
|
||||
return result != 0 ? result : 1;
|
||||
}
|
||||
|
||||
public static Object[] FindObjectsByType(System.Type type, FindObjectsInactive inactive = FindObjectsInactive.Exclude)
|
||||
{
|
||||
#if UNITY_6000_4_OR_NEWER
|
||||
return Object.FindObjectsByType(type, inactive);
|
||||
#else
|
||||
return Object.FindObjectsByType(type, inactive, FindObjectsSortMode.None);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static T[] FindObjectsByType<T>(FindObjectsInactive inactive = FindObjectsInactive.Exclude) where T : Object
|
||||
{
|
||||
#if UNITY_6000_4_OR_NEWER
|
||||
return Object.FindObjectsByType<T>(inactive);
|
||||
#else
|
||||
return Object.FindObjectsByType<T>(inactive, FindObjectsSortMode.None);
|
||||
#endif
|
||||
}
|
||||
|
||||
static Vector2Int CalculateResolution(Vector2 resolution, int maximum)
|
||||
{
|
||||
// Enforce maximum and scale to maintain aspect ratio.
|
||||
@@ -138,8 +144,17 @@ namespace WaveHarmonic.Crest
|
||||
return (T)System.Attribute.GetCustomAttribute(type, typeof(T));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="UnityEngine.WaitForEndOfFrame"/>
|
||||
/// <remarks>
|
||||
/// Does not work in batch mode or with the scene view.
|
||||
/// </remarks>
|
||||
public static WaitForEndOfFrame WaitForEndOfFrame { get; } = new();
|
||||
|
||||
public static float Fmod(float x, float y)
|
||||
{
|
||||
return x - y * (float)System.Math.Truncate(x / y);
|
||||
}
|
||||
|
||||
// Taken from:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/871df5563d88e1ba778c82a43f39c9afc95368e6/Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl#L1149-L1152
|
||||
// Z buffer to linear 0..1 depth (0 at camera position, 1 at far plane).
|
||||
@@ -374,6 +389,16 @@ namespace WaveHarmonic.Crest
|
||||
return mask == (mask | (1 << layer));
|
||||
}
|
||||
|
||||
// https://docs.unity3d.com/6000.3/Documentation/Manual/WebGPU-limitations.html
|
||||
public static bool IsWebGPU =>
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
SystemInfo.graphicsDeviceType is GraphicsDeviceType.WebGPU;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
|
||||
public static bool RequiresCustomClear => IsWebGPU || Application.platform == RuntimePlatform.PS5;
|
||||
|
||||
// R16G16B16A16_SFloat appears to be the most compatible format.
|
||||
// https://docs.unity3d.com/Manual/class-TextureImporterOverride.html#texture-compression-support-platforms
|
||||
// https://learn.microsoft.com/en-us/windows/win32/direct3d12/typed-unordered-access-view-loads#supported-formats-and-api-calls
|
||||
@@ -386,10 +411,44 @@ namespace WaveHarmonic.Crest
|
||||
&& SystemInfo.SupportsRandomWriteOnRenderTextureFormat(rtFormat);
|
||||
}
|
||||
|
||||
static GraphicsFormat GetWebGPUTextureFormat(GraphicsFormat format)
|
||||
{
|
||||
// WebGPU is very limited in format usage - especially read-write.
|
||||
return GraphicsFormatUtility.GetComponentCount(format) switch
|
||||
{
|
||||
1 => GraphicsFormat.R32_SFloat,
|
||||
_ => GraphicsFormat.R32G32B32A32_SFloat,
|
||||
};
|
||||
}
|
||||
|
||||
internal static readonly GraphicsFormatUsage s_DataGraphicsFormatUsage =
|
||||
// Ensures a non compressed format is returned. This is a prerequisite for random
|
||||
// write, but not random write itself according to a dubious comment in the
|
||||
// Graphics repository. Search UUM-91313.
|
||||
GraphicsFormatUsage.LoadStore |
|
||||
// All these textures are sampled at some point.
|
||||
GraphicsFormatUsage.Sample |
|
||||
// Always use linear filtering.
|
||||
GraphicsFormatUsage.Linear;
|
||||
|
||||
internal static GraphicsFormat GetCompatibleTextureFormat(GraphicsFormat format, GraphicsFormatUsage usage, string label, bool randomWrite = false)
|
||||
{
|
||||
var result = SystemInfo.GetCompatibleFormat(format, usage);
|
||||
var useFallback = result == GraphicsFormat.None;
|
||||
var isMetal = GraphicsDeviceType.Metal == SystemInfo.graphicsDeviceType;
|
||||
|
||||
#if CREST_DISABLE_PLATFORM_RTFORMAT_OVERRIDES
|
||||
isMetal = false;
|
||||
#endif
|
||||
|
||||
#if !UNITY_6000_0_OR_NEWER
|
||||
// Weird bug on macOS where unknown format is returned, but it is really the same
|
||||
// as the input (R32G32B32A32_SFloat).
|
||||
if (isMetal && (int)result == 89)
|
||||
{
|
||||
result = GraphicsFormat.R32G32B32A32_SFloat;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CREST_DEBUG_LOG_FORMAT_CHANGES
|
||||
if (useFallback)
|
||||
@@ -402,29 +461,57 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
#endif
|
||||
|
||||
// NOTE: Disabling for now. RenderTextureFormat is a subset of GraphicsFormat and
|
||||
// there is not always an equivalent.
|
||||
// if (!useFallback && randomWrite && !SupportsRandomWriteOnRenderTextureFormat(result))
|
||||
// {
|
||||
// Debug.Log($"Crest: The graphics device does not support the render texture format {result} with random read/write. Will attempt to use fallback.");
|
||||
// useFallback = true;
|
||||
// }
|
||||
#if !CREST_DISABLE_RANDOMWRITE_CHECK
|
||||
// Metal will return false for any two channel texture, as per the below link, but
|
||||
// they work without issue. Lets trust the API, but only for other platforms.
|
||||
// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
|
||||
if (!isMetal && !useFallback && randomWrite && !SupportsRandomWriteOnRenderTextureFormat(result))
|
||||
{
|
||||
#if CREST_DEBUG_LOG_FORMAT_CHANGES
|
||||
Debug.Log($"Crest: The graphics device does not support the render texture format {result} with random read/write. Will attempt to use fallback. ({label})");
|
||||
#endif
|
||||
|
||||
useFallback = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CREST_DEBUG_LOG_FORMAT_CHANGES
|
||||
// Check if fallback is compatible before using it.
|
||||
if (useFallback && format == s_FallbackGraphicsFormat)
|
||||
{
|
||||
Debug.Log($"Crest: Fallback {s_FallbackGraphicsFormat} is not supported on this device. Please inform us. ({label})");
|
||||
useFallback = false;
|
||||
Debug.Log($"Crest: Fallback {s_FallbackGraphicsFormat} is not supported on this device. This may be a false positive. Please inform us if you have any issues. ({label})");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (useFallback)
|
||||
{
|
||||
result = s_FallbackGraphicsFormat;
|
||||
}
|
||||
|
||||
#if !CREST_DISABLE_PLATFORM_RTFORMAT_OVERRIDES
|
||||
if (randomWrite && IsWebGPU)
|
||||
{
|
||||
// Pass the requested format otherwise GetCompatibleFormat may change the component
|
||||
// count which we need to pick the right format.
|
||||
result = GetWebGPUTextureFormat(format);
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GraphicsFormat GetCompatibleTextureFormat(GraphicsFormat format, bool randomWrite)
|
||||
{
|
||||
#if !CREST_DISABLE_PLATFORM_RTFORMAT_OVERRIDES
|
||||
if (randomWrite && IsWebGPU)
|
||||
{
|
||||
format = GetWebGPUTextureFormat(format);
|
||||
}
|
||||
#endif
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
public static void SetGlobalKeyword(string keyword, bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
@@ -711,12 +798,12 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
public static bool GetGlobalBoolean(int id)
|
||||
{
|
||||
return Shader.GetGlobalInteger(id) == 1;
|
||||
return Shader.GetGlobalFloat(id) != 0f;
|
||||
}
|
||||
|
||||
public static void SetGlobalBoolean(int id, bool value)
|
||||
{
|
||||
Shader.SetGlobalInteger(id, value ? 1 : 0);
|
||||
Shader.SetGlobalFloat(id, value ? 1f : 0f);
|
||||
}
|
||||
|
||||
#if d_UnityURP
|
||||
@@ -731,6 +818,12 @@ namespace WaveHarmonic.Crest
|
||||
internal static ScriptableRendererData[] UniversalRendererData(UniversalRenderPipelineAsset asset) =>
|
||||
(ScriptableRendererData[])s_RenderDataListField.GetValue(asset);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static readonly System.Type s_PlayModeViewType = typeof(UnityEditor.EditorWindow).Assembly.GetType("UnityEditor.PlayModeView");
|
||||
static readonly FieldInfo s_RenderingViewField = s_PlayModeViewType.GetField("s_RenderingView", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
static readonly FieldInfo s_ShowGizmosField = s_PlayModeViewType.GetField("m_ShowGizmos", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
#endif
|
||||
|
||||
internal static int GetRendererIndex(Camera camera)
|
||||
{
|
||||
var rendererIndex = (int)s_RendererIndex.GetValue(camera.GetUniversalAdditionalCameraData());
|
||||
@@ -760,6 +853,92 @@ namespace WaveHarmonic.Crest
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static void UniversalRenderCamera(ScriptableRenderContext context, Camera camera, int slice)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// Fixes when using Render Graph:
|
||||
// Attempting to render to a depth only surface with no dummy color attachment
|
||||
|
||||
var sceneView = UnityEditor.SceneView.currentDrawingSceneView;
|
||||
var drawGizmos = false;
|
||||
|
||||
if (sceneView != null)
|
||||
{
|
||||
drawGizmos = sceneView.drawGizmos;
|
||||
sceneView.drawGizmos = false;
|
||||
}
|
||||
|
||||
var gameView = s_RenderingViewField.GetValue(null);
|
||||
|
||||
if (gameView != null)
|
||||
{
|
||||
drawGizmos = (bool)s_ShowGizmosField.GetValue(gameView);
|
||||
s_ShowGizmosField.SetValue(gameView, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
// SingleCameraRequest does not render the full camera stack, thus should exclude
|
||||
// overlays which is likely desirable. Alternative approach worth investigating:
|
||||
// https://docs.unity3d.com/6000.0/Documentation/Manual/urp/User-Render-Requests.html
|
||||
// Setting destination silences a warning if Opaque Texture enabled.
|
||||
s_RenderSingleCameraRequest.destination = camera.targetTexture;
|
||||
s_RenderSingleCameraRequest.slice = slice;
|
||||
UnityEngine.Rendering.RenderPipeline.SubmitRenderRequest(camera, s_RenderSingleCameraRequest);
|
||||
#else
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
UniversalRenderPipeline.RenderSingleCamera(context, camera);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (sceneView != null)
|
||||
{
|
||||
sceneView.drawGizmos = drawGizmos;
|
||||
}
|
||||
|
||||
if (gameView != null)
|
||||
{
|
||||
s_ShowGizmosField.SetValue(gameView, drawGizmos);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void UniversalRenderCamera(ScriptableRenderContext context, Camera camera, int slice, bool noRenderFeatures)
|
||||
{
|
||||
// Get this every time as it could change.
|
||||
var renderers = (ScriptableRendererData[])s_RenderDataListField.GetValue(UniversalRenderPipeline.asset);
|
||||
var renderer = (UniversalRendererData)renderers[GetRendererIndex(camera)];
|
||||
|
||||
// On Unity 6.3, got exceptions if this was auto with SSAO enabled.
|
||||
var safe = !noRenderFeatures && renderer.intermediateTextureMode == IntermediateTextureMode.Always;
|
||||
|
||||
if (!safe)
|
||||
{
|
||||
foreach (var feature in renderer.rendererFeatures)
|
||||
{
|
||||
// Null exception reported here. Might be null due to missing render features
|
||||
if (feature == null) continue;
|
||||
s_RenderFeatureActiveStates.Add(feature.isActive);
|
||||
feature.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
UniversalRenderCamera(context, camera, slice);
|
||||
|
||||
if (!safe)
|
||||
{
|
||||
var index = 0;
|
||||
foreach (var feature in renderer.rendererFeatures)
|
||||
{
|
||||
if (feature == null) continue;
|
||||
feature.SetActive(s_RenderFeatureActiveStates[index++]);
|
||||
}
|
||||
|
||||
s_RenderFeatureActiveStates.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RenderCameraWithoutCustomPasses(Camera camera)
|
||||
{
|
||||
// Get this every time as it could change.
|
||||
@@ -791,24 +970,12 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
static readonly UnityEngine.Rendering.RenderPipeline.StandardRequest s_RenderStandardRequest = new();
|
||||
|
||||
public static void RenderCamera(Camera camera, ScriptableRenderContext context, int slice)
|
||||
public static void RenderCamera(Camera camera, ScriptableRenderContext context, int slice, bool noRenderFeatures = false)
|
||||
{
|
||||
#if d_UnityURP
|
||||
if (RenderPipelineHelper.IsUniversal)
|
||||
{
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
// SingleCameraRequest does not render the full camera stack, thus should exclude
|
||||
// overlays which is likely desirable. Alternative approach worth investigating:
|
||||
// https://docs.unity3d.com/6000.0/Documentation/Manual/urp/User-Render-Requests.html
|
||||
// Setting destination silences a warning if Opaque Texture enabled.
|
||||
s_RenderSingleCameraRequest.destination = camera.targetTexture;
|
||||
s_RenderSingleCameraRequest.slice = slice;
|
||||
UnityEngine.Rendering.RenderPipeline.SubmitRenderRequest(camera, s_RenderSingleCameraRequest);
|
||||
#else
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
UniversalRenderPipeline.RenderSingleCamera(context, camera);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
#endif
|
||||
UniversalRenderCamera(context, camera, slice, noRenderFeatures);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -894,7 +1061,7 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
static class Extensions
|
||||
static partial class Extensions
|
||||
{
|
||||
// Swizzle
|
||||
public static Vector2 XZ(this Vector3 v) => new(v.x, v.z);
|
||||
@@ -1003,6 +1170,18 @@ namespace WaveHarmonic.Crest
|
||||
return GeometryUtility.CalculateBounds(s_BoundsPoints, transform.localToWorldMatrix);
|
||||
}
|
||||
|
||||
public static Bounds Rotate(this Bounds bounds, Quaternion rotation)
|
||||
{
|
||||
var center = rotation * bounds.center;
|
||||
|
||||
// Rotation each axis separately gets closer to Unity's, but the difference is only
|
||||
// epsilon in magnitude.
|
||||
var extents = rotation * bounds.extents * 2f;
|
||||
|
||||
// Rotation can produce negatives.
|
||||
return new(center, new(Mathf.Abs(extents.x), Mathf.Abs(extents.y), Mathf.Abs(extents.z)));
|
||||
}
|
||||
|
||||
public static bool IntersectsXZ(this Bounds a, Bounds b)
|
||||
{
|
||||
return a.min.x <= b.max.x && a.max.x >= b.min.x &&
|
||||
@@ -1083,24 +1262,17 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
public static bool GetBoolean(this Material material, int id)
|
||||
{
|
||||
return (material.HasInteger(id) ? material.GetInteger(id) : material.GetInt(id)) != 0;
|
||||
return material.GetFloat(id) != 0f;
|
||||
}
|
||||
|
||||
public static void SetBoolean(this Material material, int id, bool value)
|
||||
{
|
||||
if (material.HasInteger(id))
|
||||
{
|
||||
material.SetInteger(id, value ? 1 : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.SetInt(id, value ? 1 : 0);
|
||||
}
|
||||
material.SetFloat(id, value ? 1f : 0f);
|
||||
}
|
||||
|
||||
public static void SetGlobalBoolean(this CommandBuffer buffer, int id, bool value)
|
||||
{
|
||||
buffer.SetGlobalInteger(id, value ? 1 : 0);
|
||||
buffer.SetGlobalFloat(id, value ? 1f : 0f);
|
||||
}
|
||||
|
||||
public static bool IsEmpty(this UnityEngine.Events.UnityEvent @event)
|
||||
@@ -1112,6 +1284,30 @@ namespace WaveHarmonic.Crest
|
||||
{
|
||||
return @event.GetPersistentEventCount() == 0;
|
||||
}
|
||||
|
||||
public static bool Encapsulates(this Rect r1, Rect r2)
|
||||
{
|
||||
return r1.Contains(r2.min) && r1.Contains(r2.max);
|
||||
}
|
||||
}
|
||||
|
||||
static partial class Extensions
|
||||
{
|
||||
#if !UNITY_6000_3_OR_NEWER
|
||||
internal static int GetEntityId(this Object @this)
|
||||
{
|
||||
return @this.GetInstanceID();
|
||||
}
|
||||
#endif
|
||||
|
||||
internal static ulong GetRawSceneHandle(this UnityEngine.SceneManagement.Scene @this)
|
||||
{
|
||||
#if UNITY_6000_4_OR_NEWER
|
||||
return @this.handle.GetRawData();
|
||||
#else
|
||||
return (ulong)@this.handle;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace WaveHarmonic.Crest
|
||||
public void SetVectorArray(int param, Vector4[] value) => Commands.SetGlobalVectorArray(param, value);
|
||||
public void SetMatrix(int param, Matrix4x4 value) => Commands.SetGlobalMatrix(param, value);
|
||||
public void SetInteger(int param, int value) => Commands.SetGlobalInteger(param, value);
|
||||
public void SetBoolean(int param, bool value) => Commands.SetGlobalInteger(param, value ? 1 : 0);
|
||||
public void SetBoolean(int param, bool value) => Commands.SetGlobalFloat(param, value ? 1f : 0f);
|
||||
|
||||
public void GetBlock() { }
|
||||
public void SetBlock() { }
|
||||
@@ -73,7 +73,7 @@ namespace WaveHarmonic.Crest
|
||||
public void SetVectorArray(int param, Vector4[] value) => Commands.SetGlobalVectorArray(param, value);
|
||||
public void SetMatrix(int param, Matrix4x4 value) => Commands.SetGlobalMatrix(param, value);
|
||||
public void SetInteger(int param, int value) => Commands.SetGlobalInteger(param, value);
|
||||
public void SetBoolean(int param, bool value) => Commands.SetGlobalInteger(param, value ? 1 : 0);
|
||||
public void SetBoolean(int param, bool value) => Commands.SetGlobalFloat(param, value ? 1f : 0f);
|
||||
|
||||
public void GetBlock() { }
|
||||
public void SetBlock() { }
|
||||
|
||||
@@ -23,6 +23,11 @@ namespace WaveHarmonic.Crest
|
||||
void SetBlock();
|
||||
}
|
||||
|
||||
interface IPropertyWrapperVariants : IPropertyWrapper
|
||||
{
|
||||
void SetKeyword(in LocalKeyword keyword, bool value);
|
||||
}
|
||||
|
||||
static class PropertyWrapperConstants
|
||||
{
|
||||
internal const string k_NoShaderMessage = "Cannot create required material because shader <i>{0}</i> could not be found or loaded."
|
||||
@@ -40,7 +45,7 @@ namespace WaveHarmonic.Crest
|
||||
public void SetVectorArray(int param, Vector4[] value) => Buffer.SetGlobalVectorArray(param, value);
|
||||
public void SetMatrix(int param, Matrix4x4 value) => Buffer.SetGlobalMatrix(param, value);
|
||||
public void SetInteger(int param, int value) => Buffer.SetGlobalInteger(param, value);
|
||||
public void SetBoolean(int param, bool value) => Buffer.SetGlobalInteger(param, value ? 1 : 0);
|
||||
public void SetBoolean(int param, bool value) => Buffer.SetGlobalFloat(param, value ? 1f : 0f);
|
||||
|
||||
public void GetBlock() { }
|
||||
public void SetBlock() { }
|
||||
@@ -65,14 +70,13 @@ namespace WaveHarmonic.Crest
|
||||
public void SetVectorArray(int param, Vector4[] value) => PropertyBlock.SetVectorArray(param, value);
|
||||
public void SetMatrix(int param, Matrix4x4 value) => PropertyBlock.SetMatrix(param, value);
|
||||
public void SetInteger(int param, int value) => PropertyBlock.SetInteger(param, value);
|
||||
public void SetBoolean(int param, bool value) => PropertyBlock.SetInteger(param, value ? 1 : 0);
|
||||
public void SetBoolean(int param, bool value) => PropertyBlock.SetFloat(param, value ? 1f : 0f);
|
||||
|
||||
public void GetBlock() => Renderer.GetPropertyBlock(PropertyBlock);
|
||||
public void SetBlock() => Renderer.SetPropertyBlock(PropertyBlock);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
readonly struct PropertyWrapperMaterial : IPropertyWrapper
|
||||
readonly struct PropertyWrapperMaterial : IPropertyWrapperVariants
|
||||
{
|
||||
public Material Material { get; }
|
||||
|
||||
@@ -97,7 +101,7 @@ namespace WaveHarmonic.Crest
|
||||
public void SetVectorArray(int param, Vector4[] value) => Material.SetVectorArray(param, value);
|
||||
public void SetMatrix(int param, Matrix4x4 value) => Material.SetMatrix(param, value);
|
||||
public void SetInteger(int param, int value) => Material.SetInteger(param, value);
|
||||
public void SetBoolean(int param, bool value) => Material.SetInteger(param, value ? 1 : 0);
|
||||
public void SetBoolean(int param, bool value) => Material.SetFloat(param, value ? 1f : 0f);
|
||||
|
||||
public void GetBlock() { }
|
||||
public void SetBlock() { }
|
||||
@@ -117,14 +121,13 @@ namespace WaveHarmonic.Crest
|
||||
public void SetVectorArray(int param, Vector4[] value) => MaterialPropertyBlock.SetVectorArray(param, value);
|
||||
public void SetMatrix(int param, Matrix4x4 value) => MaterialPropertyBlock.SetMatrix(param, value);
|
||||
public void SetInteger(int param, int value) => MaterialPropertyBlock.SetInteger(param, value);
|
||||
public void SetBoolean(int param, bool value) => MaterialPropertyBlock.SetInteger(param, value ? 1 : 0);
|
||||
public void SetBoolean(int param, bool value) => MaterialPropertyBlock.SetFloat(param, value ? 1f : 0f);
|
||||
|
||||
public void GetBlock() { }
|
||||
public void SetBlock() { }
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
readonly struct PropertyWrapperCompute : IPropertyWrapper
|
||||
readonly struct PropertyWrapperCompute : IPropertyWrapperVariants
|
||||
{
|
||||
readonly CommandBuffer _Buffer;
|
||||
readonly ComputeShader _Shader;
|
||||
@@ -140,7 +143,8 @@ namespace WaveHarmonic.Crest
|
||||
public void SetFloat(int param, float value) => _Buffer.SetComputeFloatParam(_Shader, param, value);
|
||||
public void SetFloatArray(int param, float[] value) => _Buffer.SetGlobalFloatArray(param, value);
|
||||
public void SetInteger(int param, int value) => _Buffer.SetComputeIntParam(_Shader, param, value);
|
||||
public void SetBoolean(int param, bool value) => _Buffer.SetComputeIntParam(_Shader, param, value ? 1 : 0);
|
||||
public void SetIntegers(int param, params int[] value) => _Buffer.SetComputeIntParams(_Shader, param, value);
|
||||
public void SetBoolean(int param, bool value) => _Buffer.SetComputeFloatParam(_Shader, param, value ? 1f : 0f);
|
||||
public void SetTexture(int param, Texture value) => _Buffer.SetComputeTextureParam(_Shader, _Kernel, param, value);
|
||||
public void SetTexture(int param, RenderTargetIdentifier value) => _Buffer.SetComputeTextureParam(_Shader, _Kernel, param, value);
|
||||
public void SetBuffer(int param, ComputeBuffer value) => _Buffer.SetComputeBufferParam(_Shader, _Kernel, param, value);
|
||||
@@ -156,8 +160,7 @@ namespace WaveHarmonic.Crest
|
||||
public void Dispatch(int x, int y, int z) => _Buffer.DispatchCompute(_Shader, _Kernel, x, y, z);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
readonly struct PropertyWrapperComputeStandalone : IPropertyWrapper
|
||||
readonly struct PropertyWrapperComputeStandalone : IPropertyWrapperVariants
|
||||
{
|
||||
readonly ComputeShader _Shader;
|
||||
readonly int _Kernel;
|
||||
@@ -171,7 +174,7 @@ namespace WaveHarmonic.Crest
|
||||
public void SetFloat(int param, float value) => _Shader.SetFloat(param, value);
|
||||
public void SetFloatArray(int param, float[] value) => _Shader.SetFloats(param, value);
|
||||
public void SetInteger(int param, int value) => _Shader.SetInt(param, value);
|
||||
public void SetBoolean(int param, bool value) => _Shader.SetBool(param, value);
|
||||
public void SetBoolean(int param, bool value) => _Shader.SetFloat(param, value ? 1f : 0f);
|
||||
public void SetTexture(int param, Texture value) => _Shader.SetTexture(_Kernel, param, value);
|
||||
public void SetBuffer(int param, ComputeBuffer value) => _Shader.SetBuffer(_Kernel, param, value);
|
||||
public void SetConstantBuffer(int param, ComputeBuffer value) => _Shader.SetConstantBuffer(param, value, 0, value.stride);
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace WaveHarmonic.Crest
|
||||
cameraData = frameData.Get<UniversalCameraData>();
|
||||
renderingData = frameData.Get<UniversalRenderingData>();
|
||||
|
||||
#if URP_COMPATIBILITY_MODE
|
||||
if (builder == null)
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
@@ -69,6 +70,7 @@ namespace WaveHarmonic.Crest
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
colorTargetHandle = resources.activeColorTexture;
|
||||
depthTargetHandle = resources.activeDepthTexture;
|
||||
|
||||
@@ -93,6 +93,7 @@ namespace WaveHarmonic.Crest
|
||||
return false;
|
||||
}
|
||||
|
||||
// Modified from:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/19ec161f3f752db865597374b3ad1b3eaf110097/Packages/com.unity.render-pipelines.universal/Runtime/RenderingUtils.cs#L697-L729
|
||||
|
||||
/// <summary>
|
||||
@@ -108,7 +109,8 @@ namespace WaveHarmonic.Crest
|
||||
/// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
|
||||
/// <param name="name">Name of the RTHandle.</param>
|
||||
/// <returns>If the RTHandle should be re-allocated</returns>
|
||||
public static bool ReAllocateIfNeeded(
|
||||
public static bool ReAllocateIfNeeded
|
||||
(
|
||||
ref RTHandle handle,
|
||||
Vector2 scaleFactor,
|
||||
in RenderTextureDescriptor descriptor,
|
||||
@@ -117,50 +119,28 @@ namespace WaveHarmonic.Crest
|
||||
bool isShadowMap = false,
|
||||
int anisoLevel = 1,
|
||||
float mipMapBias = 0,
|
||||
string name = "")
|
||||
string name = ""
|
||||
)
|
||||
{
|
||||
var usingConstantScale = handle != null && handle.useScaling && handle.scaleFactor == scaleFactor;
|
||||
if (!usingConstantScale || RTHandleNeedsReAlloc(handle, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name, true))
|
||||
// Only HDRP seems to use this?
|
||||
if (RenderPipelineHelper.IsHighDefinition)
|
||||
{
|
||||
handle?.Release();
|
||||
handle = RTHandles.Alloc(scaleFactor, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name);
|
||||
return true;
|
||||
var usingConstantScale = handle != null && handle.useScaling && handle.scaleFactor == scaleFactor;
|
||||
if (!usingConstantScale || RTHandleNeedsReAlloc(handle, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name, true))
|
||||
{
|
||||
handle?.Release();
|
||||
handle = RTHandles.Alloc(scaleFactor, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/19ec161f3f752db865597374b3ad1b3eaf110097/Packages/com.unity.render-pipelines.universal/Runtime/RenderingUtils.cs#L731-L764
|
||||
|
||||
/// <summary>
|
||||
/// Re-allocate dynamically resized RTHandle if it is not allocated or doesn't match the descriptor
|
||||
/// </summary>
|
||||
/// <param name="handle">RTHandle to check (can be null)</param>
|
||||
/// <param name="scaleFunc">Function used for the RTHandle size computation.</param>
|
||||
/// <param name="descriptor">Descriptor for the RTHandle to match</param>
|
||||
/// <param name="filterMode">Filtering mode of the RTHandle.</param>
|
||||
/// <param name="wrapMode">Addressing mode of the RTHandle.</param>
|
||||
/// <param name="isShadowMap">Set to true if the depth buffer should be used as a shadow map.</param>
|
||||
/// <param name="anisoLevel">Anisotropic filtering level.</param>
|
||||
/// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
|
||||
/// <param name="name">Name of the RTHandle.</param>
|
||||
/// <returns>If an allocation was done</returns>
|
||||
public static bool ReAllocateIfNeeded(
|
||||
ref RTHandle handle,
|
||||
ScaleFunc scaleFunc,
|
||||
in RenderTextureDescriptor descriptor,
|
||||
FilterMode filterMode = FilterMode.Point,
|
||||
TextureWrapMode wrapMode = TextureWrapMode.Repeat,
|
||||
bool isShadowMap = false,
|
||||
int anisoLevel = 1,
|
||||
float mipMapBias = 0,
|
||||
string name = "")
|
||||
{
|
||||
var usingScaleFunction = handle != null && handle.useScaling && handle.scaleFactor == Vector2.zero;
|
||||
if (!usingScaleFunction || RTHandleNeedsReAlloc(handle, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name, true))
|
||||
else
|
||||
{
|
||||
handle?.Release();
|
||||
handle = RTHandles.Alloc(scaleFunc, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name);
|
||||
return true;
|
||||
if (RTHandleNeedsReAlloc(handle, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name, false))
|
||||
{
|
||||
handle?.Release();
|
||||
handle = RTHandles.Alloc(descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -2,11 +2,18 @@
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// ENABLE_VR is defined if the platform supports XR.
|
||||
// d_UnityModuleVR is defined if the VR module is installed.
|
||||
// VR module depends on XR module (which does nothing by itself) so we only need to check the VR module.
|
||||
#if ENABLE_VR && d_UnityModuleVR
|
||||
// In Unity 6.5, the XR module replaced the VR module.
|
||||
#if ENABLE_VR
|
||||
#if UNITY_6000_5_OR_NEWER
|
||||
#if d_UnityModuleXR
|
||||
#define _XR_ENABLED
|
||||
#endif
|
||||
#else
|
||||
#if d_UnityModuleVR
|
||||
#define _XR_ENABLED
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
@@ -1,18 +1,102 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#if ENABLE_VR && d_UnityModuleVR
|
||||
#if ENABLE_VR
|
||||
#if UNITY_6000_5_OR_NEWER
|
||||
#if d_UnityModuleXR
|
||||
#define _XR_ENABLED
|
||||
#endif
|
||||
#else
|
||||
#if d_UnityModuleVR
|
||||
#define _XR_ENABLED
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.XR;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
static partial class Rendering
|
||||
{
|
||||
// Taken from Unity 6.5:
|
||||
// Packages/com.unity.render-pipelines.core/Runtime/Utilities/CoreUtils.cs
|
||||
|
||||
/// <summary>
|
||||
/// Return the GraphicsFormat of DepthStencil RenderTarget preferred for the current platform.
|
||||
/// </summary>
|
||||
/// <returns>The GraphicsFormat of DepthStencil RenderTarget preferred for the current platform.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GraphicsFormat GetDefaultDepthStencilFormat()
|
||||
{
|
||||
#if UNITY_SWITCH || UNITY_SWITCH2 || UNITY_EMBEDDED_LINUX || UNITY_QNX || UNITY_ANDROID
|
||||
return GraphicsFormat.D24_UNorm_S8_UInt;
|
||||
#else
|
||||
return GraphicsFormat.D32_SFloat_S8_UInt;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Taken from Unity 6.5:
|
||||
// Packages/com.unity.render-pipelines.core/Runtime/Utilities/CoreUtils.cs
|
||||
|
||||
/// <summary>
|
||||
/// Return the GraphicsFormat of Depth-only RenderTarget preferred for the current platform.
|
||||
/// </summary>
|
||||
/// <returns>The GraphicsFormat of Depth-only RenderTarget preferred for the current platform.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GraphicsFormat GetDefaultDepthOnlyFormat()
|
||||
{
|
||||
#if UNITY_SWITCH || UNITY_SWITCH2 || UNITY_EMBEDDED_LINUX || UNITY_QNX || UNITY_ANDROID
|
||||
return GraphicsFormatUtility.GetDepthStencilFormat(24, 0); // returns GraphicsFormat.D24_UNorm when hardware supports it
|
||||
#else
|
||||
return GraphicsFormat.D32_SFloat;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Taken from Unity 6.5:
|
||||
// Packages/com.unity.render-pipelines.core/Runtime/Utilities/CoreUtils.cs
|
||||
|
||||
/// <summary>
|
||||
/// Return the number of DepthStencil RenderTarget depth bits preferred for the current platform.
|
||||
/// </summary>
|
||||
/// <returns>The number of DepthStencil RenderTarget depth bits preferred for the current platform.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static DepthBits GetDefaultDepthBufferBits()
|
||||
{
|
||||
#if UNITY_SWITCH || UNITY_SWITCH2 || UNITY_EMBEDDED_LINUX || UNITY_QNX || UNITY_ANDROID
|
||||
return DepthBits.Depth24;
|
||||
#else
|
||||
return DepthBits.Depth32;
|
||||
#endif
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GraphicsFormat GetDefaultColorFormat(bool hdr)
|
||||
{
|
||||
return SystemInfo.GetGraphicsFormat(hdr ? DefaultFormat.HDR : DefaultFormat.LDR);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GraphicsFormat GetDefaultDepthFormat(bool stencil)
|
||||
{
|
||||
return stencil ? GetDefaultDepthStencilFormat() : GetDefaultDepthOnlyFormat();
|
||||
}
|
||||
|
||||
// URP_COMPATIBILITY_MODE = URP + UE < 6.4
|
||||
public static bool IsRenderGraph => RenderPipelineHelper.IsUniversal
|
||||
#if URP_COMPATIBILITY_MODE
|
||||
#if !UNITY_6000_0_OR_NEWER
|
||||
&& false
|
||||
#else
|
||||
&& !GraphicsSettings.GetRenderPipelineSettings<UnityEngine.Rendering.Universal.RenderGraphSettings>().enableRenderCompatibilityMode
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
public static partial class BIRP
|
||||
{
|
||||
static partial class ShaderIDs
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
|
||||
namespace WaveHarmonic.Crest.Utility
|
||||
{
|
||||
@@ -22,7 +23,7 @@ namespace WaveHarmonic.Crest.Utility
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ScriptableSingleton<T> : ScriptableObject where T : ScriptableObject
|
||||
abstract class ScriptableSingleton<T> : CustomScriptableObject where T : ScriptableObject
|
||||
{
|
||||
public static T Instance { get; private set; }
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores the version.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public abstract class Versioned : ISerializationCallbackReceiver
|
||||
{
|
||||
#pragma warning disable 414
|
||||
[@SerializeField, @HideInInspector]
|
||||
private protected int _Version;
|
||||
#pragma warning restore 414
|
||||
|
||||
private protected virtual int Version => 0;
|
||||
|
||||
private protected Versioned()
|
||||
{
|
||||
// Sets the default version. Overriden by serialized field above.
|
||||
_Version = Version;
|
||||
}
|
||||
|
||||
private protected virtual void OnMigrate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||
{
|
||||
if (_Version < Version)
|
||||
{
|
||||
OnMigrate();
|
||||
_Version = Version;
|
||||
}
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d989af1b4ea11467496672fa0a9314b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -22,10 +22,15 @@
|
||||
"define": "d_Unity_Terrain"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.modules.xr",
|
||||
"name": "com.unity.modules.vr",
|
||||
"expression": "",
|
||||
"define": "d_UnityModuleVR"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.modules.xr",
|
||||
"expression": "",
|
||||
"define": "d_UnityModuleXR"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.high-definition",
|
||||
"expression": "",
|
||||
@@ -35,6 +40,11 @@
|
||||
"name": "com.unity.render-pipelines.universal",
|
||||
"expression": "",
|
||||
"define": "d_UnityURP"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.universal",
|
||||
"expression": "(,17.3.0)",
|
||||
"define": "URP_COMPATIBILITY_MODE"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
|
||||
Reference in New Issue
Block a user