还原水插件

This commit is contained in:
2026-03-05 00:14:42 +08:00
parent 0de35591e7
commit e82f2ea6b7
270 changed files with 2773 additions and 12445 deletions

View File

@@ -10,7 +10,6 @@ using System.Runtime.CompilerServices;
[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")]

View File

@@ -103,11 +103,7 @@ namespace WaveHarmonic.Crest
sealed class Layer : Decorator { }
[Conditional(Symbols.k_UnityEditor)]
sealed class Stripped : Decorator
{
public enum Style { None, PlatformTab, }
public Stripped(Style style = Style.None, bool indent = false) { }
}
sealed class Stripped : Decorator { }
[Conditional(Symbols.k_UnityEditor)]
sealed class Delayed : Decorator { }
@@ -115,12 +111,6 @@ 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 AttachMaterialEditor : Attribute
{
@@ -163,25 +153,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)]

View File

@@ -10,7 +10,7 @@ using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering.Universal;
using WaveHarmonic.Crest.Internal;
#if !UNITY_6000_0_OR_NEWER
#if !UNITY_2023_2_OR_NEWER
using GraphicsFormatUsage = UnityEngine.Experimental.Rendering.FormatUsage;
#endif
@@ -21,6 +21,18 @@ 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");
@@ -362,14 +374,6 @@ 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
// 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
@@ -382,16 +386,6 @@ 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 GraphicsFormat GetCompatibleTextureFormat(GraphicsFormat format, GraphicsFormatUsage usage, string label, bool randomWrite = false)
{
var result = SystemInfo.GetCompatibleFormat(format, usage);
@@ -428,26 +422,9 @@ namespace WaveHarmonic.Crest
result = s_FallbackGraphicsFormat;
}
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);
}
return result;
}
public static GraphicsFormat GetCompatibleTextureFormat(GraphicsFormat format, bool randomWrite)
{
if (randomWrite && IsWebGPU)
{
format = GetWebGPUTextureFormat(format);
}
return format;
}
public static void SetGlobalKeyword(string keyword, bool enabled)
{
if (enabled)
@@ -783,58 +760,6 @@ namespace WaveHarmonic.Crest
return false;
}
internal static void UniversalRenderCamera(ScriptableRenderContext context, Camera camera, int slice)
{
#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
}
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.
@@ -866,12 +791,24 @@ namespace WaveHarmonic.Crest
static readonly UnityEngine.Rendering.RenderPipeline.StandardRequest s_RenderStandardRequest = new();
public static void RenderCamera(Camera camera, ScriptableRenderContext context, int slice, bool noRenderFeatures = false)
public static void RenderCamera(Camera camera, ScriptableRenderContext context, int slice)
{
#if d_UnityURP
if (RenderPipelineHelper.IsUniversal)
{
UniversalRenderCamera(context, camera, slice, noRenderFeatures);
#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
return;
}
#endif
@@ -1175,33 +1112,6 @@ 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);
}
}
namespace Compatibility
{
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
}
}
}
}

View File

@@ -23,11 +23,6 @@ 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."
@@ -77,7 +72,7 @@ namespace WaveHarmonic.Crest
}
[System.Serializable]
readonly struct PropertyWrapperMaterial : IPropertyWrapperVariants
readonly struct PropertyWrapperMaterial : IPropertyWrapper
{
public Material Material { get; }
@@ -129,7 +124,7 @@ namespace WaveHarmonic.Crest
}
[System.Serializable]
readonly struct PropertyWrapperCompute : IPropertyWrapperVariants
readonly struct PropertyWrapperCompute : IPropertyWrapper
{
readonly CommandBuffer _Buffer;
readonly ComputeShader _Shader;
@@ -162,7 +157,7 @@ namespace WaveHarmonic.Crest
}
[System.Serializable]
readonly struct PropertyWrapperComputeStandalone : IPropertyWrapperVariants
readonly struct PropertyWrapperComputeStandalone : IPropertyWrapper
{
readonly ComputeShader _Shader;
readonly int _Kernel;

View File

@@ -61,7 +61,6 @@ 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
@@ -70,7 +69,6 @@ namespace WaveHarmonic.Crest
#pragma warning restore CS0618 // Type or member is obsolete
}
else
#endif
{
colorTargetHandle = resources.activeColorTexture;
depthTargetHandle = resources.activeDepthTexture;

View File

@@ -93,7 +93,6 @@ 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>
@@ -109,8 +108,7 @@ 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,
@@ -119,28 +117,50 @@ namespace WaveHarmonic.Crest
bool isShadowMap = false,
int anisoLevel = 1,
float mipMapBias = 0,
string name = ""
)
string name = "")
{
// Only HDRP seems to use this?
if (RenderPipelineHelper.IsHighDefinition)
var usingConstantScale = handle != null && handle.useScaling && handle.scaleFactor == scaleFactor;
if (!usingConstantScale || RTHandleNeedsReAlloc(handle, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name, 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;
}
handle?.Release();
handle = RTHandles.Alloc(scaleFactor, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name);
return true;
}
else
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))
{
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;
}
handle?.Release();
handle = RTHandles.Alloc(scaleFunc, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name);
return true;
}
return false;

View File

@@ -5,91 +5,14 @@
#define _XR_ENABLED
#endif
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
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<RenderGraphSettings>().enableRenderCompatibilityMode
#endif
#endif
;
public static partial class BIRP
{
static partial class ShaderIDs

View File

@@ -35,11 +35,6 @@
"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