From a25f4faea5526d1a2be4c2ac8c8821f828c3eeec Mon Sep 17 00:00:00 2001 From: ZYB Date: Thu, 21 Sep 2023 16:54:49 +0900 Subject: [PATCH] =?UTF-8?q?=E5=86=97=E9=95=B7=E3=81=AA=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E7=B0=A1=E7=95=A5=E5=8C=96=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Scripts/ApplyDistortionPass.cs | 28 ++++--------------- .../Core/Scripts/DistortedUvBufferPass.cs | 8 ++---- .../Core/Scripts/ScreenSpaceDistortion.cs | 5 ++-- .../Shaders/ParticlesApplyDistortion.shader | 1 - 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/Assets/Nova/Runtime/Core/Scripts/ApplyDistortionPass.cs b/Assets/Nova/Runtime/Core/Scripts/ApplyDistortionPass.cs index 74a59e4..8fd8ccb 100644 --- a/Assets/Nova/Runtime/Core/Scripts/ApplyDistortionPass.cs +++ b/Assets/Nova/Runtime/Core/Scripts/ApplyDistortionPass.cs @@ -11,32 +11,24 @@ namespace Nova.Runtime.Core.Scripts public sealed class ApplyDistortionPass : ScriptableRenderPass { private const string RenderPassName = nameof(ApplyDistortionPass); - private const string SrcToDestProfilingSamplerName = "SrcToDest"; - private readonly bool _applyToSceneView; private readonly int _distortionBufferPropertyId = Shader.PropertyToID("_ScreenSpaceUvTexture"); private readonly int _mainTexPropertyId = Shader.PropertyToID("_MainTex"); private readonly Material _material; - private readonly ProfilingSampler _srcToDestProfilingSampler; private readonly ProfilingSampler _renderPassProfilingSampler; - private ScriptableRenderer _renderer; private RenderTargetIdentifier _distortedUvBufferIdentifier; - private RenderTargetHandle _tempRenderTargetHandle; public ApplyDistortionPass(bool applyToSceneView, Shader shader) { _applyToSceneView = applyToSceneView; - _srcToDestProfilingSampler = new ProfilingSampler(SrcToDestProfilingSamplerName); _renderPassProfilingSampler = new ProfilingSampler(RenderPassName); - _tempRenderTargetHandle.Init("_TempRT"); _material = CoreUtils.CreateEngineMaterial(shader); renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing; } - public void Setup(ScriptableRenderer renderer, RenderTargetIdentifier distortedUvBufferIdentifier) + public void Setup(RenderTargetIdentifier distortedUvBufferIdentifier) { - _renderer = renderer; _distortedUvBufferIdentifier = distortedUvBufferIdentifier; } @@ -62,26 +54,16 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData } var source = renderingData.cameraData.renderer.cameraColorTargetHandle.nameID; #else - var source = _renderer.cameraColorTarget; + var source = renderingData.cameraData.renderer.cameraColorTarget; #endif var cmd = CommandBufferPool.Get(); cmd.Clear(); using (new ProfilingScope(cmd, _renderPassProfilingSampler)) { - var tempTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor; - tempTargetDescriptor.depthBufferBits = 0; - cmd.GetTemporaryRT(_tempRenderTargetHandle.id, tempTargetDescriptor); - - using (new ProfilingScope(cmd, _srcToDestProfilingSampler)) - { - cmd.SetGlobalTexture(_mainTexPropertyId, source); - cmd.SetGlobalTexture(_distortionBufferPropertyId, _distortedUvBufferIdentifier); - Blit(cmd, source, _tempRenderTargetHandle.Identifier(), _material); - } - - Blit(cmd, _tempRenderTargetHandle.Identifier(), source); - cmd.ReleaseTemporaryRT(_tempRenderTargetHandle.id); + cmd.SetGlobalTexture(_mainTexPropertyId, source); + cmd.SetGlobalTexture(_distortionBufferPropertyId, _distortedUvBufferIdentifier); + Blit(cmd, ref renderingData, _material); } context.ExecuteCommandBuffer(cmd); diff --git a/Assets/Nova/Runtime/Core/Scripts/DistortedUvBufferPass.cs b/Assets/Nova/Runtime/Core/Scripts/DistortedUvBufferPass.cs index c14bd69..52eeabb 100644 --- a/Assets/Nova/Runtime/Core/Scripts/DistortedUvBufferPass.cs +++ b/Assets/Nova/Runtime/Core/Scripts/DistortedUvBufferPass.cs @@ -2,7 +2,6 @@ // Copyright 2021 CyberAgent, Inc. // -------------------------------------------------------------- -using System; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; @@ -15,7 +14,6 @@ public sealed class DistortedUvBufferPass : ScriptableRenderPass private readonly ProfilingSampler _profilingSampler = new ProfilingSampler(ProfilerTag); private readonly RenderQueueRange _renderQueueRange = RenderQueueRange.all; private readonly ShaderTagId _shaderTagId; - private Func _getCameraDepthTargetIdentifier; private FilteringSettings _filteringSettings; #if UNITY_2022_1_OR_NEWER @@ -37,11 +35,9 @@ public void Setup(RTHandle renderTargetRTHandle) _renderTargetRTHandle = renderTargetRTHandle; } #else - public void Setup(RenderTargetIdentifier renderTargetIdentifier, - Func getCameraDepthTargetIdentifier) + public void Setup(RenderTargetIdentifier renderTargetIdentifier) { _renderTargetIdentifier = renderTargetIdentifier; - _getCameraDepthTargetIdentifier = getCameraDepthTargetIdentifier; } #endif @@ -50,7 +46,7 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera #if UNITY_2022_1_OR_NEWER ConfigureTarget(_renderTargetRTHandle); #else - ConfigureTarget(_renderTargetIdentifier, _getCameraDepthTargetIdentifier.Invoke()); + ConfigureTarget(_renderTargetIdentifier); #endif ConfigureClear(ClearFlag.Color, Color.gray); } diff --git a/Assets/Nova/Runtime/Core/Scripts/ScreenSpaceDistortion.cs b/Assets/Nova/Runtime/Core/Scripts/ScreenSpaceDistortion.cs index 5a83838..c2803fb 100644 --- a/Assets/Nova/Runtime/Core/Scripts/ScreenSpaceDistortion.cs +++ b/Assets/Nova/Runtime/Core/Scripts/ScreenSpaceDistortion.cs @@ -54,9 +54,8 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD cameraTargetDescriptor.height, 0, distortedUvBufferFormat, RenderTextureReadWrite.Default, cameraTargetDescriptor.msaaSamples); var distortedUvBufferIdentifier = new RenderTargetIdentifier(distortedUvBuffer); - - _distortedUvBufferPass.Setup(distortedUvBufferIdentifier, () => renderer.cameraDepthTarget); - _applyDistortionPass.Setup(renderer, distortedUvBufferIdentifier); + _distortedUvBufferPass.Setup(distortedUvBufferIdentifier); + _applyDistortionPass.Setup(distortedUvBufferIdentifier); #endif renderer.EnqueuePass(_distortedUvBufferPass); renderer.EnqueuePass(_applyDistortionPass); diff --git a/Assets/Nova/Runtime/Core/Shaders/ParticlesApplyDistortion.shader b/Assets/Nova/Runtime/Core/Shaders/ParticlesApplyDistortion.shader index 8bd1c87..497984d 100644 --- a/Assets/Nova/Runtime/Core/Shaders/ParticlesApplyDistortion.shader +++ b/Assets/Nova/Runtime/Core/Shaders/ParticlesApplyDistortion.shader @@ -8,7 +8,6 @@ Shader "Hidden/Nova/Particles/ApplyDistortion" #pragma vertex Vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" - #if UNITY_VERSION >= 202200 #include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl" #endif