diff --git a/Assets/Scripts/Fsr2Controller.cs b/Assets/Scripts/Fsr2Controller.cs index 29f57d2..2c1ac17 100644 --- a/Assets/Scripts/Fsr2Controller.cs +++ b/Assets/Scripts/Fsr2Controller.cs @@ -39,21 +39,6 @@ public class Fsr2Controller : MonoBehaviour private RenderTexture _outputRT; - private Material _copyDepthMat; - private Material CopyDepthMaterial - { - get - { - if (_copyDepthMat == null) - { - var copyDepthShader = Fsr2.GlobalCallbacks.LoadShader("Shaders/FSR2_CopyDepth"); - _copyDepthMat = new Material(copyDepthShader); - } - - return _copyDepthMat; - } - } - private Material _copyMotionMat; private Material CopyMotionVectorsMaterial { @@ -126,17 +111,12 @@ public class Fsr2Controller : MonoBehaviour { var color = gameCamera.targetTexture; - // I hate having to allocate extra RTs just to duplicate already existing Unity render buffers, but AFAIK there is no way to directly address these buffers individually from code - var depth = RenderTexture.GetTemporary(color.width, color.height, 0, RenderTextureFormat.RFloat); + // I hate having to allocate extra RTs just to duplicate already existing Unity render buffers, but AFAIK there is no way to directly address motion vectors from code var motionVectors = RenderTexture.GetTemporary(color.width, color.height, 0, RenderTextureFormat.RGHalf); - - // TODO: might be able to combine color + depth into a single RT and separate them out using RenderTextureSubElement - // TODO: we can copy to all RTs at the same time using a multi-target blit, requiring only a single shader + material - Graphics.Blit(color, depth, CopyDepthMaterial); Graphics.Blit(color, motionVectors, CopyMotionVectorsMaterial); _dispatchDescription.Color = color; - _dispatchDescription.Depth = depth; + _dispatchDescription.Depth = color; _dispatchDescription.MotionVectors = motionVectors; _dispatchDescription.Output = _outputRT; _dispatchDescription.Exposure = null; @@ -154,7 +134,6 @@ public class Fsr2Controller : MonoBehaviour _context.Dispatch(_dispatchDescription); - RenderTexture.ReleaseTemporary(depth); RenderTexture.ReleaseTemporary(motionVectors); // Output upscaled image to screen diff --git a/Assets/Scripts/Fsr2Pipeline.cs b/Assets/Scripts/Fsr2Pipeline.cs index 21a89b7..cbc3132 100644 --- a/Assets/Scripts/Fsr2Pipeline.cs +++ b/Assets/Scripts/Fsr2Pipeline.cs @@ -173,7 +173,7 @@ namespace FidelityFX // - How do we clear the resources that need to be cleared at dispatch? (SetBufferData) // - Shouldn't we use a ComputeBuffer for resources that are one-dimensional and clearly not image data? e.g. SPD atomic counter & Lanczos LUT data - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.Color); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.Color, 0, RenderTextureSubElement.Color); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, UavAutoExposure, _autoExposure); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbSpd, _spdConstants, 0, Marshal.SizeOf()); @@ -196,8 +196,8 @@ namespace FidelityFX public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.Color); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputDepth, dispatchParams.Depth); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.Color, 0, RenderTextureSubElement.Color); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputDepth, dispatchParams.Depth, 0, RenderTextureSubElement.Depth); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputMotionVectors, dispatchParams.MotionVectors); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure); @@ -228,8 +228,8 @@ namespace FidelityFX commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvTransparencyAndCompositionMask, dispatchParams.Reactive); // Default reactive mask, as we don't support TCR (yet) commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvPrevDilatedMotionVectors, _dilatedMotionVectors[frameIndex ^ 1]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputMotionVectors, dispatchParams.MotionVectors); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.Color); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputDepth, dispatchParams.Depth); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.Color, 0, RenderTextureSubElement.Color); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputDepth, dispatchParams.Depth, 0, RenderTextureSubElement.Depth); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf()); @@ -318,7 +318,7 @@ namespace FidelityFX { // Run the RCAS sharpening filter on the upscaled image commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvRcasInput, dispatchParams.Color); // TODO: should be output from accumulate pass + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvRcasInput, dispatchParams.Color, 0, RenderTextureSubElement.Color); // TODO: should be output from accumulate pass commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, UavUpscaledOutput, dispatchParams.Output); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbRcas, _rcasConstants, 0, Marshal.SizeOf());