using System.Runtime.InteropServices; namespace UnityEngine.Rendering.PostProcessing { internal class SGSR2Upscaler_2PassFS: SGSR2Upscaler { protected override string VariantName => "SGSR2 2-Pass Fragment"; private PropertySheet _sheet; private readonly RenderTargetIdentifier[] _mrt = new RenderTargetIdentifier[2]; public override void CreateContext(PostProcessRenderContext context, Upscaling config) { base.CreateContext(context, config); _sheet = new PropertySheet(new Material(context.resources.shaders.sgsr2Upscaler.twoPassFragment)); } public override void DestroyContext() { _sheet.Release(); base.DestroyContext(); } protected override void DoRender(CommandBuffer cmd, PostProcessRenderContext context, Upscaling config) { uint frameIndex = _frameCount % 2; cmd.SetGlobalTexture("InputColor", context.source); _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.BlitFullscreenTriangle(BuiltinRenderTextureType.None, _mrt, BuiltinRenderTextureType.None, _sheet, 1); } } }