升级水插件
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#if d_UnityHDRP
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
@@ -14,36 +12,20 @@ namespace WaveHarmonic.Crest
|
||||
static SampleShadowsHDRP s_Instance;
|
||||
static readonly string s_Name = "Sample Shadows";
|
||||
|
||||
// These values come from unity_MatrxVP value in the frame debugger. unity_MatrxVP is marked as legacy and
|
||||
// breaks XR SPI. It is defined in:
|
||||
// "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/EditorShaderVariables.hlsl"
|
||||
static readonly Matrix4x4 s_Matrix = new
|
||||
(
|
||||
new(2f, 0f, 0f, 0f),
|
||||
new(0f, -2f, 0f, 0f),
|
||||
new(0f, 0f, 0.00990099f, 0f),
|
||||
new(-1f, 1f, 0.990099f, 1f)
|
||||
);
|
||||
|
||||
static class ShaderIDs
|
||||
{
|
||||
public static readonly int s_ViewProjectionMatrix = Shader.PropertyToID("_Crest_ViewProjectionMatrix");
|
||||
}
|
||||
|
||||
GameObject _GameObject;
|
||||
WaterRenderer _Water;
|
||||
int _XrTargetEyeIndex = -1;
|
||||
|
||||
protected override void Execute(CustomPassContext context)
|
||||
{
|
||||
var water = WaterRenderer.Instance;
|
||||
var water = _Water;
|
||||
|
||||
if (water == null || !water._ShadowLod.Enabled)
|
||||
if (!water._ShadowLod.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!WaterRenderer.IsWithinEditorUpdate || EditorApplication.isPaused)
|
||||
if (!WaterRenderer.IsWithinEditorUpdate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -58,36 +40,19 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
camera.TryGetComponent<HDAdditionalCameraData>(out var cameraData);
|
||||
|
||||
if (cameraData != null && cameraData.xrRendering)
|
||||
// Skip the right eye for multi-pass as data is not stereo.
|
||||
if (Rendering.HDRP.SkipPassXR(ref _XrTargetEyeIndex, cameraData))
|
||||
{
|
||||
XRHelpers.UpdatePassIndex(ref _XrTargetEyeIndex);
|
||||
|
||||
// Skip the right eye as data is not stereo.
|
||||
if (_XrTargetEyeIndex == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable for XR SPI otherwise input will not have correct world position.
|
||||
if (cameraData != null && cameraData.xrRendering && XRHelpers.IsSinglePass)
|
||||
{
|
||||
context.cmd.DisableShaderKeyword("STEREO_INSTANCING_ON");
|
||||
}
|
||||
Rendering.HDRP.DisableXR(context.cmd, cameraData);
|
||||
|
||||
// We cannot seem to override this matrix so a reference manually.
|
||||
context.cmd.SetGlobalMatrix(ShaderIDs.s_ViewProjectionMatrix, s_Matrix);
|
||||
water._ShadowLod.BuildCommandBuffer(water, context.cmd);
|
||||
|
||||
// Restore matrices otherwise remaining render will have incorrect matrices. Each pass is responsible for
|
||||
// restoring matrices if required.
|
||||
context.cmd.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix);
|
||||
|
||||
// Restore XR SPI as we cannot rely on remaining pipeline to do it for us.
|
||||
if (cameraData != null && cameraData.xrRendering && XRHelpers.IsSinglePass)
|
||||
{
|
||||
context.cmd.EnableShaderKeyword("STEREO_INSTANCING_ON");
|
||||
}
|
||||
Rendering.HDRP.EnableXR(context.cmd, cameraData);
|
||||
}
|
||||
|
||||
internal static void Enable(WaterRenderer water)
|
||||
@@ -103,11 +68,12 @@ namespace WaveHarmonic.Crest
|
||||
(
|
||||
gameObject,
|
||||
ref s_Instance,
|
||||
s_Name,
|
||||
CustomPassInjectionPoint.BeforeTransparent
|
||||
WaterRenderer.k_DrawLodData,
|
||||
// Earliest point after shadow maps have populated.
|
||||
CustomPassInjectionPoint.AfterOpaqueAndSky
|
||||
);
|
||||
|
||||
s_Instance._GameObject = gameObject;
|
||||
s_Instance._Water = water;
|
||||
}
|
||||
|
||||
internal static void Disable()
|
||||
|
||||
Reference in New Issue
Block a user