还原水插件
This commit is contained in:
@@ -20,9 +20,6 @@ namespace WaveHarmonic.Crest
|
||||
readonly System.Action<CommandBuffer> _CopyColorTexture;
|
||||
readonly System.Action<CommandBuffer> _SetRenderTargetToBackBuffers;
|
||||
|
||||
bool _AllocatedColor;
|
||||
GraphicsFormat _GraphicsFormat;
|
||||
|
||||
public UnderwaterEffectPass(UnderwaterRenderer renderer)
|
||||
{
|
||||
_Renderer = renderer;
|
||||
@@ -43,8 +40,6 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
public void Allocate(GraphicsFormat format)
|
||||
{
|
||||
_GraphicsFormat = format;
|
||||
|
||||
if (_Renderer.RenderBeforeTransparency && !_Renderer._NeedsColorTexture)
|
||||
{
|
||||
return;
|
||||
@@ -62,8 +57,6 @@ namespace WaveHarmonic.Crest
|
||||
wrapMode: TextureWrapMode.Clamp,
|
||||
name: "_Crest_UnderwaterCameraColorTexture"
|
||||
);
|
||||
|
||||
_AllocatedColor = true;
|
||||
}
|
||||
|
||||
public void ReAllocate(RenderTextureDescriptor descriptor)
|
||||
@@ -92,11 +85,6 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
if (!_Renderer.RenderBeforeTransparency || _Renderer._NeedsColorTexture)
|
||||
{
|
||||
if (!_AllocatedColor)
|
||||
{
|
||||
Allocate(_GraphicsFormat);
|
||||
}
|
||||
|
||||
buffer.SetGlobalTexture(UnderwaterRenderer.ShaderIDs.s_CameraColorTexture, _ColorTexture);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
}
|
||||
|
||||
#if URP_COMPATIBILITY_MODE
|
||||
[System.Obsolete]
|
||||
public override void OnCameraSetup(CommandBuffer buffer, ref RenderingData data)
|
||||
{
|
||||
@@ -47,7 +46,6 @@ namespace WaveHarmonic.Crest
|
||||
context.ExecuteCommandBuffer(buffer);
|
||||
CommandBufferPool.Release(buffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
partial class CopyDepthBufferPassURP
|
||||
@@ -65,7 +63,6 @@ namespace WaveHarmonic.Crest
|
||||
var resources = frameData.Get<UniversalResourceData>();
|
||||
cameraData = frameData.Get<UniversalCameraData>();
|
||||
|
||||
#if URP_COMPATIBILITY_MODE
|
||||
if (builder == null)
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
@@ -74,7 +71,6 @@ namespace WaveHarmonic.Crest
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// We need reset render targets to these before the next pass, but we do not read
|
||||
// or write to the color target.
|
||||
@@ -103,7 +99,6 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
}
|
||||
|
||||
#if URP_COMPATIBILITY_MODE
|
||||
[System.Obsolete]
|
||||
public override void OnCameraSetup(CommandBuffer buffer, ref RenderingData data)
|
||||
{
|
||||
@@ -120,7 +115,6 @@ namespace WaveHarmonic.Crest
|
||||
context.ExecuteCommandBuffer(buffer);
|
||||
CommandBufferPool.Release(buffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace WaveHarmonic.Crest
|
||||
if (UseStencilBuffer)
|
||||
{
|
||||
descriptor.colorFormat = RenderTextureFormat.Depth;
|
||||
descriptor.depthBufferBits = (int)Rendering.GetDefaultDepthBufferBits();
|
||||
descriptor.depthBufferBits = (int)Helpers.k_DepthBits;
|
||||
// bindMS is necessary in this case for depth.
|
||||
descriptor.SetMSAASamples(camera);
|
||||
descriptor.bindMS = descriptor.msaaSamples > 1;
|
||||
@@ -272,9 +272,9 @@ namespace WaveHarmonic.Crest
|
||||
if (camera.cameraType != CameraType.Reflection)
|
||||
{
|
||||
// Skip work if camera is far enough below the surface.
|
||||
var forceFullShader = !_MaskRead || (_Water._PerCameraHeightReady && _Water._ViewerHeightAboveWaterPerCamera < -8f && !Portaled);
|
||||
var forceFullShader = !_Water.Surface.Enabled || (_Water._ViewerHeightAboveWaterPerCamera < -8f && !Portaled);
|
||||
_VolumeMaterial.SetKeyword("d_Crest_NoMaskColor", forceFullShader);
|
||||
_VolumeMaterial.SetKeyword("d_Crest_NoMaskDepth", !_MaskRead || RenderBeforeTransparency);
|
||||
_VolumeMaterial.SetKeyword("d_Crest_NoMaskDepth", !_Water.Surface.Enabled || RenderBeforeTransparency);
|
||||
}
|
||||
|
||||
// Compute ambient lighting SH.
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Only repaint, otherwise changes might persist.
|
||||
if (Event.current?.type != EventType.Repaint)
|
||||
if (Event.current.type != EventType.Repaint)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -91,14 +91,12 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
// Portals have their own fitted to the portal bounds.
|
||||
else
|
||||
#pragma warning disable format
|
||||
#if d_CrestPortals
|
||||
if (!Portaled || _Water.Portals.RequiresFullScreenMask)
|
||||
#endif
|
||||
{
|
||||
RenderLineMask(commands, camera, mask.ColorRT.descriptor, mask._ColorRTI);
|
||||
}
|
||||
#pragma warning restore format
|
||||
}
|
||||
|
||||
internal void RenderLineMask(CommandBuffer buffer, Camera camera, RenderTextureDescriptor descriptor, RenderTargetIdentifier target)
|
||||
@@ -201,12 +199,12 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
MaskRenderer.MaskInput MaskRenderer.IMaskProvider.Allocate()
|
||||
{
|
||||
return UseLegacyMask || UseStencilBuffer ? MaskRenderer.MaskInput.Both : MaskRenderer.MaskInput.Color;
|
||||
return MaskRenderer.MaskInput.Both;
|
||||
}
|
||||
|
||||
MaskRenderer.MaskInput MaskRenderer.IMaskReceiver.Allocate()
|
||||
{
|
||||
return UseLegacyMask || UseStencilBuffer ? MaskRenderer.MaskInput.Both : MaskRenderer.MaskInput.Color;
|
||||
return MaskRenderer.MaskInput.Both;
|
||||
}
|
||||
|
||||
MaskRenderer.MaskInput MaskRenderer.IMaskProvider.Write(Camera camera)
|
||||
@@ -217,7 +215,7 @@ namespace WaveHarmonic.Crest
|
||||
_DoneMaskRead = true;
|
||||
}
|
||||
|
||||
return _MaskRead ? (UseLegacyMask || UseStencilBuffer ? MaskRenderer.MaskInput.Both : MaskRenderer.MaskInput.Color) : MaskRenderer.MaskInput.None;
|
||||
return _MaskRead ? _Water.Surface.Enabled ? MaskRenderer.MaskInput.Both : MaskRenderer.MaskInput.Color : MaskRenderer.MaskInput.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace WaveHarmonic.Crest
|
||||
[System.Serializable]
|
||||
public sealed partial class UnderwaterRenderer
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
internal const float k_CullLimitMinimum = 0.000001f;
|
||||
internal const float k_CullLimitMaximum = 0.01f;
|
||||
|
||||
@@ -67,11 +72,10 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
[@Heading("Advanced")]
|
||||
|
||||
[Tooltip("Rules to exclude cameras from rendering underwater.\n\nThese are exclusion rules, so for all cameras, select Nothing. These rules are applied on top of the Layer rules.")]
|
||||
[@DecoratedField]
|
||||
[Tooltip("Whether to execute for all cameras.\n\nIf disabled, then additionally ignore any camera that is not the view camera or our reflection camera. It will require managing culling masks of all cameras.")]
|
||||
[@GenerateAPI]
|
||||
[SerializeField]
|
||||
internal WaterCameraExclusion _CameraExclusions = WaterCameraExclusion.Hidden | WaterCameraExclusion.Reflection;
|
||||
[@DecoratedField, SerializeField]
|
||||
bool _AllCameras;
|
||||
|
||||
[Tooltip("Copying parameters each frame ensures underwater appearance stays consistent with the water surface.\n\nHas a small overhead so should be disabled if not needed.")]
|
||||
[@GenerateAPI]
|
||||
@@ -128,7 +132,7 @@ namespace WaveHarmonic.Crest
|
||||
internal bool RenderBeforeTransparency => false;
|
||||
#else
|
||||
// Legacy mask works except for negative volumes. Not officially supported.
|
||||
internal bool UseLegacyMask => false;
|
||||
internal bool UseLegacyMask => _AllCameras;
|
||||
internal bool RenderBeforeTransparency => true;
|
||||
#endif
|
||||
|
||||
@@ -249,11 +253,6 @@ namespace WaveHarmonic.Crest
|
||||
_HorizonMaskMaterial = null;
|
||||
}
|
||||
|
||||
internal bool ShouldRender(Camera camera)
|
||||
{
|
||||
return ShouldRender(camera, Pass.Effect);
|
||||
}
|
||||
|
||||
internal bool ShouldRender(Camera camera, Pass pass)
|
||||
{
|
||||
if (!_Enabled || _Material == null)
|
||||
@@ -272,7 +271,7 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
|
||||
// Skip entire mask pass if possible.
|
||||
if (pass == Pass.Mask && !_Water.Surface.ShouldRender(camera))
|
||||
if (pass == Pass.Mask && !_Water.Surface.Enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -291,23 +290,29 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_Debug._OnlyReflectionCameras && camera.cameraType != CameraType.Reflection)
|
||||
var isReflectionCamera = camera.cameraType == CameraType.Reflection;
|
||||
|
||||
// Mask or culling is not needed for reflections.
|
||||
if (isReflectionCamera && pass != Pass.Effect)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var isPlanarReflectionCamera = camera == _Water.Reflections.ReflectionCamera;
|
||||
if (_Debug._OnlyReflectionCameras && !isReflectionCamera)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Option to exclude cameras that is not the view camera or our reflection camera.
|
||||
// Otherwise, filtering depends on the camera's culling mask which is not always
|
||||
// accessible like with the global "Reflection Probes Camera". But whether those
|
||||
// cameras triggering camera events is a bug is TBD as it is intermittent.
|
||||
if (camera != _Water.Reflections.ReflectionCamera && !WaterRenderer.ShouldRender(camera, _CameraExclusions))
|
||||
if (!_AllCameras && camera != _Water.GetViewer(includeSceneCamera: false) && camera.cameraType != CameraType.SceneView && camera != WaterReflections.CurrentCamera)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_Debug._DisableHeightAboveWaterOptimization && !Portaled && _Water.Surface.ShouldRender(camera))
|
||||
if (!_Debug._DisableHeightAboveWaterOptimization && !Portaled)
|
||||
{
|
||||
_Water.UpdatePerCameraHeight(camera);
|
||||
_ViewerWaterHeight = _Water._ViewerHeightAboveWaterPerCamera;
|
||||
@@ -340,11 +345,6 @@ namespace WaveHarmonic.Crest
|
||||
OnBeginCameraRendering(camera);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (_VolumeMaterial == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Populated by this point.
|
||||
if (_VolumeMaterial.shader != WaterResources.Instance.Shaders._UnderwaterEffect)
|
||||
{
|
||||
@@ -352,7 +352,6 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma warning disable format
|
||||
#if d_UnityURP
|
||||
if (RenderPipelineHelper.IsUniversal)
|
||||
{
|
||||
@@ -372,7 +371,6 @@ namespace WaveHarmonic.Crest
|
||||
{
|
||||
OnBeforeLegacyRender(camera);
|
||||
}
|
||||
#pragma warning restore format
|
||||
}
|
||||
|
||||
internal void OnBeginCameraRendering(Camera camera)
|
||||
@@ -382,6 +380,12 @@ namespace WaveHarmonic.Crest
|
||||
return;
|
||||
}
|
||||
|
||||
// Only one camera supported due to LOD center dependency.
|
||||
if (!UseLegacyMask && ShouldRender(camera, Pass.Mask) && camera == _Water.Viewer)
|
||||
{
|
||||
_Water.Surface.UpdateDisplacedSurfaceData(camera);
|
||||
}
|
||||
|
||||
#if d_UnityHDRP
|
||||
if (RenderPipelineHelper.IsHighDefinition)
|
||||
{
|
||||
@@ -462,13 +466,6 @@ namespace WaveHarmonic.Crest
|
||||
UpdateEnvironmentalLighting(camera, extinction, _ViewerWaterHeight);
|
||||
}
|
||||
|
||||
// Only relevant to cameras rendering the surface from here.
|
||||
if (!_Water.Surface.ShouldRender(camera))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Redo culling. Culling is per camera. But chunks are shared.
|
||||
if (Portaled || _ViewerWaterHeight > -5f)
|
||||
{
|
||||
RevertCulling();
|
||||
@@ -510,28 +507,6 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
}
|
||||
|
||||
internal void ExecuteHeightField(Camera camera)
|
||||
{
|
||||
if (UseLegacyMask)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if d_CrestPortals
|
||||
if (Portaled && !_Water.Portals.RequiresFullScreenMask)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!ShouldRender(camera, Pass.Mask))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_Water.Surface.UpdateDisplacedSurfaceData(camera);
|
||||
}
|
||||
|
||||
void SetEnabled(bool previous, bool current)
|
||||
{
|
||||
if (previous == current) return;
|
||||
@@ -562,21 +537,4 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Obsolete / Migration
|
||||
partial class UnderwaterRenderer
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
// No migration as default value for new control is far more effective than this toggle.
|
||||
[System.Obsolete("Please use Camera Exclusion instead.")]
|
||||
[Tooltip("Whether to execute for all cameras.\n\nIf disabled, then additionally ignore any camera that is not the view camera or our reflection camera. It will require managing culling masks of all cameras.")]
|
||||
[@GenerateAPI]
|
||||
[@DecoratedField, SerializeField]
|
||||
[HideInInspector]
|
||||
bool _AllCameras;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user