From 9f4b96ea2589d8867c5bfed80cb5a402ceaece89 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 28 Dec 2024 14:46:20 +0100 Subject: [PATCH] Made integration more PPV2-like by using property sheets, material property blocks and the BlitFullScreenTriangle method. --- .../Upscaling/SGSR2Upscaler_2PassFS.cs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler_2PassFS.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler_2PassFS.cs index df39c3f..1fca768 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler_2PassFS.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler_2PassFS.cs @@ -6,19 +6,19 @@ namespace UnityEngine.Rendering.PostProcessing { protected override string VariantName => "SGSR2 2-Pass Fragment"; - private Material _material; + private PropertySheet _sheet; private readonly RenderTargetIdentifier[] _mrt = new RenderTargetIdentifier[2]; public override void CreateContext(PostProcessRenderContext context, Upscaling config) { base.CreateContext(context, config); - _material = new Material(context.resources.shaders.sgsr2Upscaler.twoPassFragment); + _sheet = new PropertySheet(new Material(context.resources.shaders.sgsr2Upscaler.twoPassFragment)); } public override void DestroyContext() { - RuntimeUtilities.Destroy(_material); + _sheet.Release(); base.DestroyContext(); } @@ -27,19 +27,16 @@ namespace UnityEngine.Rendering.PostProcessing { uint frameIndex = _frameCount % 2; - // TODO: try using a PropertySheet here again, now that PPV2 is functional cmd.SetGlobalTexture("InputColor", context.source); - cmd.SetGlobalTexture("MotionDepthClipAlphaBuffer", _motionDepthClipAlpha); - cmd.SetGlobalTexture("PrevOutput", _upscaleHistory[frameIndex ^ 1]); - cmd.SetGlobalConstantBuffer(_paramsBuffer, "cbSGSR2", 0, Marshal.SizeOf()); - - cmd.SetRenderTarget(_motionDepthClipAlpha, context.source); - cmd.DrawMesh(RuntimeUtilities.fullscreenTriangle, Matrix4x4.identity, _material, 0, 0); + _sheet.properties.SetTexture("MotionDepthClipAlphaBuffer", _motionDepthClipAlpha); + _sheet.properties.SetTexture("PrevOutput", _upscaleHistory[frameIndex ^ 1]); + _sheet.properties.SetConstantBuffer("cbSGSR2", _paramsBuffer, 0, Marshal.SizeOf()); + cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, _motionDepthClipAlpha, _sheet, 0); + _mrt[0] = context.destination; _mrt[1] = _upscaleHistory[frameIndex]; - cmd.SetRenderTarget(_mrt, context.destination); - cmd.DrawMesh(RuntimeUtilities.fullscreenTriangle, Matrix4x4.identity, _material, 0, 1); + cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, _mrt, BuiltinRenderTextureType.None, _sheet, 1); } } }