Development repository for FSR2 integration into Unity Post-Processing Stack V2.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.8 KiB

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<SGSR2.Params>());
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);
}
}
}