Browse Source

Fixes to jitter which at least produces a stable picture now. Still not actually right, but making progress.

mac-autoexp
Nico de Poel 3 years ago
parent
commit
25f1742728
  1. 1
      Assets/Scripts/Fsr2Controller.cs
  2. 16
      Assets/Scripts/SubsampleTest.cs

1
Assets/Scripts/Fsr2Controller.cs

@ -69,7 +69,6 @@ public class Fsr2Controller : MonoBehaviour
RenderPipelineManager.endContextRendering += OnEndContextRendering;
// TODO: destroy and recreate context on screen resolution and/or quality mode change
// TODO: enable motion vector jitter cancellation or not?
_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?

16
Assets/Scripts/SubsampleTest.cs

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using FidelityFX;
using UnityEngine;
@ -84,6 +85,13 @@ public class SubsampleTest : MonoBehaviour
private void Update()
{
if (Input.GetKeyDown(KeyCode.F12))
{
string path = Path.Combine(Directory.GetCurrentDirectory(), $"screenshot-{DateTime.Now:yyyyMMdd-HHmmss}.png");
ScreenCapture.CaptureScreenshot(path);
Debug.Log($"Screenshot saved to: {path}");
}
outputCamera.enabled = gameCamera.enabled;
//outputCamera.CopyFrom(gameCamera);
@ -105,14 +113,14 @@ public class SubsampleTest : MonoBehaviour
// Unity already does jittering behind the scenes for certain post-effects, so can we perhaps integrate with that?
int jitterPhaseCount = Fsr2.GetJitterPhaseCount(gameCamera.targetTexture.width, Screen.width);
Fsr2.GetJitterOffset(out float jitterX, out float jitterY, Time.frameCount, jitterPhaseCount);
jitterX = 2.0f * jitterX / gameCamera.targetTexture.width;
_fsr2Controller.SetJitterOffset(new Vector2(jitterX, jitterY));
jitterX = -2.0f * jitterX / gameCamera.targetTexture.width;
jitterY = -2.0f * jitterY / gameCamera.targetTexture.height;
var jitterTranslationMatrix = Matrix4x4.Translate(new Vector3(jitterX, jitterY, 0));
gameCamera.projectionMatrix = jitterTranslationMatrix * gameCamera.nonJitteredProjectionMatrix;
_fsr2Controller.SetJitterOffset(new Vector2(jitterX, jitterY));
}
else
{

Loading…
Cancel
Save