升级水插件
This commit is contained in:
@@ -7,7 +7,6 @@ using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
using UnityEngine.Rendering.RendererUtils;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
@@ -17,13 +16,11 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
static UnderwaterRenderer s_Renderer;
|
||||
static UnderwaterEffectPass s_UnderwaterEffectPass;
|
||||
static UnderwaterEffectPassHDRP s_Instance;
|
||||
internal static UnderwaterEffectPassHDRP s_Instance;
|
||||
static CopyDepthBufferPassHDRP s_CopyDepthBufferPassHDRP;
|
||||
|
||||
static ShaderTagId[] s_ForwardShaderTags;
|
||||
|
||||
GameObject _GameObject;
|
||||
|
||||
public static void Enable(UnderwaterRenderer renderer)
|
||||
{
|
||||
var gameObject = CustomPassHelpers.CreateOrUpdate
|
||||
@@ -37,25 +34,24 @@ namespace WaveHarmonic.Crest
|
||||
(
|
||||
gameObject,
|
||||
ref s_CopyDepthBufferPassHDRP,
|
||||
"Copy Depth Buffer",
|
||||
UnderwaterRenderer.k_DrawVolume,
|
||||
CustomPassInjectionPoint.AfterOpaqueDepthAndNormal
|
||||
);
|
||||
|
||||
var isBeforeTransparentPass = renderer.RenderBeforeTransparency;
|
||||
|
||||
CustomPassHelpers.CreateOrUpdate
|
||||
(
|
||||
gameObject,
|
||||
ref s_Instance,
|
||||
k_Name,
|
||||
CustomPassInjectionPoint.BeforePostProcess
|
||||
UnderwaterRenderer.k_DrawVolume,
|
||||
GetInjectionPoint(isBeforeTransparentPass),
|
||||
// Higher number (priority) means execute earlier. Volume executes first.
|
||||
priority: 1
|
||||
);
|
||||
|
||||
s_Instance._GameObject = gameObject;
|
||||
|
||||
s_Renderer = renderer;
|
||||
s_UnderwaterEffectPass = new(renderer);
|
||||
|
||||
RenderPipelineManager.beginCameraRendering -= s_Instance.OnBeginCameraRendering;
|
||||
RenderPipelineManager.beginCameraRendering += s_Instance.OnBeginCameraRendering;
|
||||
}
|
||||
|
||||
public static void Disable()
|
||||
@@ -68,9 +64,17 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
}
|
||||
|
||||
void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera)
|
||||
static CustomPassInjectionPoint GetInjectionPoint(bool isBeforeTransparentPass)
|
||||
{
|
||||
return isBeforeTransparentPass
|
||||
? CustomPassInjectionPoint.BeforeTransparent
|
||||
: CustomPassInjectionPoint.BeforePostProcess;
|
||||
}
|
||||
|
||||
internal void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera)
|
||||
{
|
||||
s_CopyDepthBufferPassHDRP.enabled = s_Renderer.UseStencilBuffer;
|
||||
s_Instance._Volume.injectionPoint = GetInjectionPoint(s_Renderer.RenderBeforeTransparency);
|
||||
}
|
||||
|
||||
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
|
||||
@@ -94,8 +98,6 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
protected override void Cleanup()
|
||||
{
|
||||
RenderPipelineManager.beginCameraRendering -= s_Instance.OnBeginCameraRendering;
|
||||
|
||||
s_UnderwaterEffectPass?.Release();
|
||||
}
|
||||
|
||||
@@ -108,44 +110,15 @@ namespace WaveHarmonic.Crest
|
||||
return;
|
||||
}
|
||||
|
||||
// Allocate here in case user changes options and we skipped allocation in Setup.
|
||||
s_UnderwaterEffectPass.Allocate(context.cameraColorBuffer.rt.graphicsFormat);
|
||||
|
||||
// Create a separate stencil buffer context by using a depth buffer copy if needed.
|
||||
var depthBuffer = s_Renderer.UseStencilBuffer
|
||||
? s_CopyDepthBufferPassHDRP._DepthBufferCopy
|
||||
: context.cameraDepthBuffer;
|
||||
|
||||
s_UnderwaterEffectPass.Execute(camera, context.cmd, context.cameraColorBuffer, depthBuffer, context.propertyBlock);
|
||||
|
||||
// Renders transparent objects after the underwater effect. Using the correct
|
||||
// shader, the above water portion of the object is rendered normally (in the
|
||||
// transparent pass), and the below water portion is rendered here with underwater
|
||||
// applied.
|
||||
// See the following for reference:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/DrawRenderersCustomPass.cs
|
||||
if (s_Renderer.EnableShaderAPI)
|
||||
{
|
||||
var renderConfig = HDUtils.GetRendererConfiguration
|
||||
(
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
context.hdCamera.frameSettings.IsEnabled(FrameSettingsField.AdaptiveProbeVolume),
|
||||
#else
|
||||
context.hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolume),
|
||||
#endif
|
||||
context.hdCamera.frameSettings.IsEnabled(FrameSettingsField.Shadowmask)
|
||||
);
|
||||
|
||||
var result = new RendererListDesc(s_ForwardShaderTags, context.cullingResults, context.hdCamera.camera)
|
||||
{
|
||||
rendererConfiguration = renderConfig,
|
||||
renderQueueRange = GetRenderQueueRange(RenderQueueType.AllTransparent),
|
||||
sortingCriteria = SortingCriteria.CommonTransparent,
|
||||
excludeObjectMotionVectors = false,
|
||||
layerMask = s_Renderer._TransparentObjectLayers,
|
||||
};
|
||||
|
||||
context.cmd.EnableShaderKeyword(UnderwaterRenderer.k_KeywordUnderwaterObjects);
|
||||
CoreUtils.DrawRendererList(context.renderContext, context.cmd, context.renderContext.CreateRendererList(result));
|
||||
context.cmd.DisableShaderKeyword(UnderwaterRenderer.k_KeywordUnderwaterObjects);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,13 +139,11 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
var buffer = context.cmd;
|
||||
|
||||
buffer.SetRenderTarget(BuiltinRenderTextureType.None, _DepthBufferCopy);
|
||||
buffer.ClearRenderTarget(RTClearFlags.Depth, Color.black, 1, 0);
|
||||
|
||||
// NOTE: previously we cleared the target depth first due to artifacts.
|
||||
buffer.CopyTexture(context.cameraDepthBuffer.rt, _DepthBufferCopy.rt);
|
||||
|
||||
// Clear the stencil component just in case.
|
||||
buffer.ClearRenderTarget(RTClearFlags.Stencil, Color.black, 1, 0);
|
||||
CoreUtils.SetRenderTarget(buffer, BuiltinRenderTextureType.None, _DepthBufferCopy, ClearFlag.Stencil);
|
||||
}
|
||||
|
||||
protected override void Cleanup()
|
||||
|
||||
Reference in New Issue
Block a user