Browse Source

Some minor optimizations and cleanup

mac-autoexp
Nico de Poel 3 years ago
parent
commit
f184be7b62
  1. 12
      Assets/Scripts/Fsr2Controller.cs
  2. 17
      Assets/Scripts/SubsampleTest.cs

12
Assets/Scripts/Fsr2Controller.cs

@ -68,11 +68,11 @@ public class Fsr2Controller : MonoBehaviour
if (!_started)
return;
_context = Fsr2.CreateContext(DisplaySize, RenderSize, Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation | Fsr2.InitializationFlags.EnableFP16Usage);
_context = Fsr2.CreateContext(DisplaySize, RenderSize, Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation);
// TODO: do we need a depth buffer for the output? We will need depth & motion vectors for subsequent post-FX. How should FSR2 output these?
// TODO: can probably be a temporary RT
_upscaledOutput = new RenderTexture(DisplaySize.x, DisplaySize.y, 24, RenderTextureFormat.ARGBHalf) { name = "FSR2 Upscaled Output", enableRandomWrite = true };
_upscaledOutput = new RenderTexture(DisplaySize.x, DisplaySize.y, 0, RenderTextureFormat.ARGBHalf) { name = "FSR2 Upscaled Output", enableRandomWrite = true };
_upscaledOutput.Create();
}
@ -105,6 +105,9 @@ public class Fsr2Controller : MonoBehaviour
var motionVectors = RenderTexture.GetTemporary(renderBuffer.width, renderBuffer.height, 0, RenderTextureFormat.RGHalf);
Graphics.Blit(renderBuffer, motionVectors, CopyMotionVectorsMaterial);
// TODO: if `dest` is null, we are rendering straight to the backbuffer and should use a temporary RT as the output buffer for FSR2
// TODO: if `dest` it NOT null, we have more image effects lined up after this one, and we should be able to have FSR2 output straight to `dest` without an intermediary temp RT
_dispatchDescription.ColorDepth = renderBuffer;
_dispatchDescription.MotionVectors = motionVectors;
_dispatchDescription.Output = _upscaledOutput;
@ -126,10 +129,11 @@ public class Fsr2Controller : MonoBehaviour
_context.Dispatch(_dispatchDescription);
RenderTexture.ReleaseTemporary(motionVectors);
// Output upscaled image to screen
// TODO: we should probably use a shader to include depth & motion vectors into the output
// TODO: if `dest` is null, we likely don't care about the depth & motion vectors anymore
Graphics.Blit(_upscaledOutput, dest);
RenderTexture.ReleaseTemporary(motionVectors);
}
}

17
Assets/Scripts/SubsampleTest.cs

@ -38,11 +38,15 @@ public class SubsampleTest : MonoBehaviour
//outputCameraObject.transform.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
outputCamera = outputCameraObject.AddComponent<Camera>();
//outputCamera.CopyFrom(gameCamera);
outputCamera.backgroundColor = Color.clear;
outputCamera.clearFlags = CameraClearFlags.Nothing;
outputCamera.eventMask = 0;
outputCamera.cullingMask = 0;
outputCamera.clearFlags = CameraClearFlags.Nothing;
outputCamera.useOcclusionCulling = false;
outputCamera.orthographic = true;
outputCamera.allowMSAA = false;
outputCamera.renderingPath = RenderingPath.Forward;
_fsr2Controller = outputCameraObject.AddComponent<Fsr2Controller>();
}
@ -58,9 +62,9 @@ public class SubsampleTest : MonoBehaviour
24, // Can we copy depth value from original camera?
RenderTextureFormat.ARGBHalf); // Can we copy format from original camera? Or renderer quality settings?
gameCamera.depthTextureMode = DepthTextureMode.Depth | DepthTextureMode.DepthNormals | DepthTextureMode.MotionVectors;
gameCamera.depthTextureMode |= DepthTextureMode.Depth | DepthTextureMode.MotionVectors;
gameCamera.targetTexture.name = "FSR2 Source Texture";
gameCamera.targetTexture.name = "FSR2 Input Texture";
gameCamera.targetTexture.Create();
// Adjust texture mipmap LOD bias by log2(renderResolution/displayResolution) - 1.0;
@ -94,9 +98,6 @@ public class SubsampleTest : MonoBehaviour
}
outputCamera.enabled = gameCamera.enabled;
//outputCamera.CopyFrom(gameCamera);
outputCamera.clearFlags = CameraClearFlags.Color;
if (Screen.width != _prevScreenSize.x || Screen.height != _prevScreenSize.y || qualityMode != _prevQualityMode)
{

Loading…
Cancel
Save