using System.Runtime.InteropServices; namespace UnityEngine.Rendering.PostProcessing { internal class SGSR2Upscaler_2PassFS: SGSR2Upscaler { protected override string VariantName => "SGSR2 2-Pass Fragment"; private Material _material; 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); } public override void DestroyContext() { RuntimeUtilities.Destroy(_material); base.DestroyContext(); } protected override void DoRender(CommandBuffer cmd, PostProcessRenderContext context, Upscaling config) { 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); _mrt[0] = context.destination; _mrt[1] = _upscaleHistory[frameIndex]; cmd.SetRenderTarget(_mrt, context.destination); cmd.DrawMesh(RuntimeUtilities.fullscreenTriangle, Matrix4x4.identity, _material, 0, 1); } } }