还原水插件

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

@@ -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