升级水插件

This commit is contained in:
2026-01-08 22:30:55 +08:00
parent febff82d24
commit ca68084264
415 changed files with 18138 additions and 7134 deletions

View File

@@ -16,14 +16,15 @@ namespace WaveHarmonic.Crest
RTHandle _ColorTarget;
RTHandle _DepthTarget;
bool _FirstRender = true;
readonly System.Action<CommandBuffer> _CopyColorTexture;
readonly System.Action<CommandBuffer> _SetRenderTargetToBackBuffers;
public UnderwaterEffectPass(UnderwaterRenderer renderer)
{
_Renderer = renderer;
_CopyColorTexture = new(CopyColorTexture);
_SetRenderTargetToBackBuffers = new(SetRenderTargetToBackBuffers);
}
void CopyColorTexture(CommandBuffer buffer)
@@ -32,10 +33,20 @@ namespace WaveHarmonic.Crest
CoreUtils.SetRenderTarget(buffer, _ColorTarget, _DepthTarget, ClearFlag.None);
}
void SetRenderTargetToBackBuffers(CommandBuffer commands)
{
CoreUtils.SetRenderTarget(commands, _ColorTarget, _DepthTarget, ClearFlag.None);
}
public void Allocate(GraphicsFormat format)
{
if (_Renderer.RenderBeforeTransparency && !_Renderer._NeedsColorTexture)
{
return;
}
// TODO: There may other settings we want to set or bring in. Not MSAA since this is a resolved texture.
_ColorTexture = RTHandles.Alloc
_ColorTexture ??= RTHandles.Alloc
(
Vector2.one,
TextureXR.slices,
@@ -50,6 +61,11 @@ namespace WaveHarmonic.Crest
public void ReAllocate(RenderTextureDescriptor descriptor)
{
if (_Renderer.RenderBeforeTransparency && !_Renderer._NeedsColorTexture)
{
return;
}
// Descriptor will not have MSAA bound.
RenderPipelineCompatibilityHelper.ReAllocateIfNeeded(ref _ColorTexture, descriptor, name: "_Crest_UnderwaterCameraColorTexture");
}
@@ -62,22 +78,32 @@ namespace WaveHarmonic.Crest
public void Execute(Camera camera, CommandBuffer buffer, RTHandle color, RTHandle depth, MaterialPropertyBlock mpb = null)
{
_Renderer.UpdateEffectMaterial(camera, _FirstRender);
_Renderer.UpdateEffectMaterial(camera);
_ColorTarget = color;
_DepthTarget = depth;
CopyColorTexture(buffer);
buffer.SetGlobalTexture(UnderwaterRenderer.ShaderIDs.s_CameraColorTexture, _ColorTexture);
if (!_Renderer.RenderBeforeTransparency || _Renderer._NeedsColorTexture)
{
buffer.SetGlobalTexture(UnderwaterRenderer.ShaderIDs.s_CameraColorTexture, _ColorTexture);
}
_Renderer.ExecuteEffect(camera, buffer, _CopyColorTexture, mpb);
if (!_Renderer.RenderBeforeTransparency)
{
CopyColorTexture(buffer);
}
else
{
// TODO: needed for HDRP, but can set it on pass instead.
CoreUtils.SetRenderTarget(buffer, _ColorTarget, _DepthTarget, ClearFlag.None);
}
_Renderer.ExecuteEffect(camera, buffer, _CopyColorTexture, _SetRenderTargetToBackBuffers, mpb);
// The last pass (uber post) does not resolve the texture.
// Although, this is wasteful if the pass after this does a resolve.
// Possibly a bug with Unity?
buffer.ResolveAntiAliasedSurface(color);
_FirstRender = false;
}
}
}