Browse Source

Made integration more PPV2-like by using property sheets, material property blocks and the BlitFullScreenTriangle method.

sgsr2_fs
Nico de Poel 1 year ago
parent
commit
9f4b96ea25
  1. 19
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler_2PassFS.cs

19
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<SGSR2.Params>());
_sheet.properties.SetTexture("MotionDepthClipAlphaBuffer", _motionDepthClipAlpha);
_sheet.properties.SetTexture("PrevOutput", _upscaleHistory[frameIndex ^ 1]);
_sheet.properties.SetConstantBuffer("cbSGSR2", _paramsBuffer, 0, Marshal.SizeOf<SGSR2.Params>());
cmd.SetRenderTarget(_motionDepthClipAlpha, context.source);
cmd.DrawMesh(RuntimeUtilities.fullscreenTriangle, Matrix4x4.identity, _material, 0, 0);
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);
}
}
}
Loading…
Cancel
Save