升级水插件
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
using WaveHarmonic.Crest.Utility;
|
||||
|
||||
@@ -14,55 +11,51 @@ namespace WaveHarmonic.Crest
|
||||
/// <summary>
|
||||
/// <see cref="DepthProbe"/>'s update mode.
|
||||
/// </summary>
|
||||
[@GenerateDoc]
|
||||
public enum DepthProbeMode
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="DepthProbe"/> is updating in real-time, in accordance to <see cref="DepthProbeRefreshMode"/>.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Generated.DepthProbeMode.RealTime"/>
|
||||
[Tooltip("Update in real-time in accordance to refresh mode.")]
|
||||
RealTime,
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="DepthProbe"/> is baked in the Editor.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Generated.DepthProbeMode.Baked"/>
|
||||
[Tooltip("Baked in the editor.")]
|
||||
Baked,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How the <see cref="DepthProbe"/> refreshes when using <see cref="DepthProbeMode.RealTime"/>.
|
||||
/// </summary>
|
||||
[@GenerateDoc]
|
||||
public enum DepthProbeRefreshMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Populates the <see cref="DepthProbe"/> in Start.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Generated.DepthProbeRefreshMode.OnStart"/>
|
||||
[Tooltip("Populates the DepthProbe in Start.")]
|
||||
OnStart = 0,
|
||||
|
||||
// EveryFrame = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Requires manual updating via <see cref="DepthProbe.Populate"/>.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Generated.DepthProbeRefreshMode.ViaScripting"/>
|
||||
[Tooltip("Requires manual updating via DepthProbe.Populate.")]
|
||||
ViaScripting = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How a component is placed in the world.
|
||||
/// </summary>
|
||||
[@GenerateDoc]
|
||||
public enum Placement
|
||||
{
|
||||
/// <summary>
|
||||
/// The component is in a fixed position.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Generated.Placement.Fixed"/>
|
||||
[Tooltip("The component is in a fixed position.")]
|
||||
Fixed,
|
||||
|
||||
/// <summary>
|
||||
/// The component follows the transform.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Generated.Placement.Transform"/>
|
||||
[Tooltip("The component follows the transform.")]
|
||||
Transform,
|
||||
|
||||
/// <summary>
|
||||
/// The component follows the viewpoint.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Generated.Placement.Viewpoint"/>
|
||||
[Tooltip("The component follows the viewpoint.")]
|
||||
Viewpoint,
|
||||
}
|
||||
|
||||
@@ -317,17 +310,6 @@ namespace WaveHarmonic.Crest
|
||||
public static readonly int s_VoronoiPingPong1 = Shader.PropertyToID("_Crest_VoronoiPingPong1");
|
||||
}
|
||||
|
||||
#if d_UnityHDRP
|
||||
static readonly List<FrameSettingsField> s_FrameSettingsFields = new()
|
||||
{
|
||||
FrameSettingsField.OpaqueObjects,
|
||||
FrameSettingsField.TransparentObjects,
|
||||
FrameSettingsField.TransparentPrepass,
|
||||
FrameSettingsField.TransparentPostpass,
|
||||
FrameSettingsField.AsyncCompute,
|
||||
};
|
||||
#endif
|
||||
|
||||
internal void Bind<T>(T wrapper) where T : IPropertyWrapper
|
||||
{
|
||||
wrapper.SetTexture(ShaderIDs.s_DepthProbe, Texture);
|
||||
@@ -446,39 +428,13 @@ namespace WaveHarmonic.Crest
|
||||
if (RenderPipelineHelper.IsUniversal)
|
||||
{
|
||||
#if d_UnityURP
|
||||
var additionalCameraData = _Camera.GetUniversalAdditionalCameraData();
|
||||
additionalCameraData.renderShadows = false;
|
||||
additionalCameraData.requiresColorTexture = false;
|
||||
additionalCameraData.requiresDepthTexture = false;
|
||||
additionalCameraData.renderPostProcessing = false;
|
||||
additionalCameraData.allowXRRendering = false;
|
||||
SetUpCameraURP();
|
||||
#endif
|
||||
}
|
||||
else if (RenderPipelineHelper.IsHighDefinition)
|
||||
{
|
||||
#if d_UnityHDRP
|
||||
var additionalCameraData = _Camera.gameObject.AddComponent<HDAdditionalCameraData>();
|
||||
|
||||
additionalCameraData.clearColorMode = HDAdditionalCameraData.ClearColorMode.Color;
|
||||
additionalCameraData.volumeLayerMask = 0;
|
||||
additionalCameraData.probeLayerMask = 0;
|
||||
additionalCameraData.xrRendering = false;
|
||||
|
||||
// Override camera frame settings to disable most of the expensive rendering for this camera.
|
||||
// Most importantly, disable custom passes and post-processing as third-party stuff might throw
|
||||
// errors because of this camera. Even with excluding a lot of HDRP features, it still does a
|
||||
// lit pass which is not cheap.
|
||||
additionalCameraData.customRenderingSettings = true;
|
||||
|
||||
foreach (FrameSettingsField frameSetting in System.Enum.GetValues(typeof(FrameSettingsField)))
|
||||
{
|
||||
if (!s_FrameSettingsFields.Contains(frameSetting))
|
||||
{
|
||||
// Enable override and then disable the feature.
|
||||
additionalCameraData.renderingPathCustomFrameSettingsOverrideMask.mask[(uint)frameSetting] = true;
|
||||
additionalCameraData.renderingPathCustomFrameSettings.SetEnabled(frameSetting, false);
|
||||
}
|
||||
}
|
||||
SetUpCameraHD();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -557,6 +513,10 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
OnBeforeRender?.Invoke(this);
|
||||
|
||||
_CommandBuffer ??= new();
|
||||
_CommandBuffer.Clear();
|
||||
_CommandBuffer.name = "Crest.DepthProbe";
|
||||
|
||||
#if UNITY_EDITOR
|
||||
try
|
||||
#endif
|
||||
@@ -566,6 +526,9 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
if (_FillHolesCaptureHeight > 0f)
|
||||
{
|
||||
Graphics.ExecuteCommandBuffer(_CommandBuffer);
|
||||
_CommandBuffer.Clear();
|
||||
|
||||
// Fill holes pass.
|
||||
RenderDepthIntoProbe(k_FillKernel, _CaptureRange.y + _FillHolesCaptureHeight);
|
||||
}
|
||||
@@ -588,10 +551,14 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
if (_GenerateSignedDistanceField)
|
||||
{
|
||||
_CommandBuffer.BeginSample("SDF");
|
||||
RenderSignedDistanceField(inverted: false);
|
||||
RenderSignedDistanceField(inverted: true);
|
||||
_CommandBuffer.EndSample("SDF");
|
||||
}
|
||||
|
||||
Graphics.ExecuteCommandBuffer(_CommandBuffer);
|
||||
|
||||
HashState(ref _RenderedStateHash);
|
||||
}
|
||||
|
||||
@@ -621,9 +588,17 @@ namespace WaveHarmonic.Crest
|
||||
backFaces = RenderTexture.GetTemporary(target.descriptor);
|
||||
_Camera.targetTexture = backFaces;
|
||||
|
||||
// Does not work for HDRP (handled elsewhere).
|
||||
var oldInvertCulling = GL.invertCulling;
|
||||
GL.invertCulling = true;
|
||||
|
||||
#if d_UnityHDRP
|
||||
if (RenderPipelineHelper.IsHighDefinition)
|
||||
{
|
||||
_HDAdditionalCameraData.invertFaceCulling = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Render scene, saving depths in depth buffer.
|
||||
#if d_UnityURP
|
||||
if (RenderPipelineHelper.IsUniversal)
|
||||
@@ -637,6 +612,14 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
|
||||
_Camera.targetTexture = target;
|
||||
|
||||
#if d_UnityHDRP
|
||||
if (RenderPipelineHelper.IsHighDefinition)
|
||||
{
|
||||
_HDAdditionalCameraData.invertFaceCulling = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
GL.invertCulling = oldInvertCulling;
|
||||
}
|
||||
|
||||
@@ -652,7 +635,7 @@ namespace WaveHarmonic.Crest
|
||||
_Camera.Render();
|
||||
}
|
||||
|
||||
var wrapper = new PropertyWrapperComputeStandalone(WaterResources.Instance.Compute._RenderDepthProbe, kernel);
|
||||
var wrapper = new PropertyWrapperCompute(_CommandBuffer, WaterResources.Instance.Compute._RenderDepthProbe, kernel);
|
||||
|
||||
wrapper.SetFloat(ShaderIDs.s_HeightOffset, transform.position.y);
|
||||
|
||||
@@ -699,13 +682,12 @@ namespace WaveHarmonic.Crest
|
||||
return;
|
||||
}
|
||||
|
||||
var buffer = _CommandBuffer;
|
||||
|
||||
var cameraToWorldMatrix = _Camera.cameraToWorldMatrix;
|
||||
var projectionMatrix = _Camera.projectionMatrix;
|
||||
var projectionToWorldMatrix = cameraToWorldMatrix * projectionMatrix.inverse;
|
||||
|
||||
var buffer = _CommandBuffer ??= new();
|
||||
buffer.Clear();
|
||||
buffer.name = "Jump Flood";
|
||||
// Common uniforms.
|
||||
buffer.SetComputeFloatParam(shader, DepthLodInput.ShaderIDs.s_HeightOffset, transform.position.y);
|
||||
buffer.SetComputeIntParam(shader, Crest.ShaderIDs.s_TextureSize, _Resolution);
|
||||
@@ -802,7 +784,6 @@ namespace WaveHarmonic.Crest
|
||||
);
|
||||
}
|
||||
|
||||
Graphics.ExecuteCommandBuffer(buffer);
|
||||
buffer.ReleaseTemporaryRT(voronoiPingPong0);
|
||||
buffer.ReleaseTemporaryRT(voronoiPingPong1);
|
||||
}
|
||||
@@ -929,6 +910,7 @@ namespace WaveHarmonic.Crest
|
||||
wrapper.SetVector(Crest.ShaderIDs.s_TextureSize, _Probe.Scale);
|
||||
wrapper.SetVector(Crest.ShaderIDs.s_TexturePosition, position.XZ());
|
||||
wrapper.SetVector(Crest.ShaderIDs.s_TextureRotation, new Vector2(matrix.m20, matrix.m00).normalized);
|
||||
wrapper.SetVector(Crest.ShaderIDs.s_Multiplier, Vector4.one);
|
||||
wrapper.SetInteger(Crest.ShaderIDs.s_Blend, (int)LodInputBlend.Maximum);
|
||||
wrapper.SetTexture(Crest.ShaderIDs.s_Texture, _Probe.Texture);
|
||||
wrapper.SetTexture(Crest.ShaderIDs.s_Target, target);
|
||||
@@ -962,9 +944,9 @@ namespace WaveHarmonic.Crest
|
||||
Hash.AddBool(_EnableBackFaceInclusion, ref hash);
|
||||
Hash.AddInt(_AdditionalJumpFloodRounds, ref hash);
|
||||
Hash.AddBool(_GenerateSignedDistanceField, ref hash);
|
||||
Hash.AddObject(Position, ref hash);
|
||||
Hash.AddObject(Rotation, ref hash);
|
||||
Hash.AddObject(Scale, ref hash);
|
||||
Hash.AddObject(Managed ? Vector3.zero : Position, ref hash);
|
||||
Hash.AddObject(Managed ? Quaternion.identity : Rotation, ref hash);
|
||||
Hash.AddObject(Managed ? Vector2.zero : Scale, ref hash);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
@@ -992,7 +974,7 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_Debug._ForceAlwaysUpdateDebug)
|
||||
if (_Debug._ForceAlwaysUpdateDebug && _Type != DepthProbeMode.Baked)
|
||||
{
|
||||
Populate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user