Browse Source

- Use non-jittered camera projection matrix

- Double checked jitter offset values
- Use prepared (i.e. copied) motion vector texture
pssr
Nico de Poel 1 year ago
parent
commit
2ecc2d54b9
  1. 14
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/PSSRUpscaler.cs
  2. 6
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute

14
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/PSSRUpscaler.cs

@ -14,6 +14,7 @@ namespace UnityEngine.Rendering.PostProcessing
private RenderTexture _inputColor; private RenderTexture _inputColor;
private RenderTexture _inputDepth; private RenderTexture _inputDepth;
private RenderTexture _inputMotionVectors;
private RenderTexture _outputColor; private RenderTexture _outputColor;
private Texture2D _outputIntermediate; private Texture2D _outputIntermediate;
@ -39,6 +40,7 @@ namespace UnityEngine.Rendering.PostProcessing
CreateRenderTexture(ref _inputColor, "PSSR Input Color", config.MaxRenderSize, context.sourceFormat, true); CreateRenderTexture(ref _inputColor, "PSSR Input Color", config.MaxRenderSize, context.sourceFormat, true);
CreateRenderTexture(ref _inputDepth, "PSSR Input Depth", config.MaxRenderSize, GraphicsFormat.R32_SFloat, true); CreateRenderTexture(ref _inputDepth, "PSSR Input Depth", config.MaxRenderSize, GraphicsFormat.R32_SFloat, true);
CreateRenderTexture(ref _inputMotionVectors, "PSSR Input Motion Vectors", config.MaxRenderSize, GraphicsFormat.R16G16_SFloat, true);
CreateRenderTexture(ref _outputColor, "PSSR Output Color", config.UpscaleSize, RenderTextureFormat.RGB111110Float); CreateRenderTexture(ref _outputColor, "PSSR Output Color", config.UpscaleSize, RenderTextureFormat.RGB111110Float);
if (PSSRPlugin.CreatePssrContext(ref initParams, out IntPtr outputColorTexturePtr) >= 0 && outputColorTexturePtr != IntPtr.Zero) if (PSSRPlugin.CreatePssrContext(ref initParams, out IntPtr outputColorTexturePtr) >= 0 && outputColorTexturePtr != IntPtr.Zero)
@ -83,8 +85,6 @@ namespace UnityEngine.Rendering.PostProcessing
} }
} }
private static readonly int CameraMotionVectorsTexture = Shader.PropertyToID("_CameraMotionVectorsTexture");
public override void Render(PostProcessRenderContext context, Upscaling config) public override void Render(PostProcessRenderContext context, Upscaling config)
{ {
var cmd = context.command; var cmd = context.command;
@ -97,11 +97,11 @@ namespace UnityEngine.Rendering.PostProcessing
cmd.BeginSample("PSSR"); cmd.BeginSample("PSSR");
// TODO: if PSSR needs a copy of the previous depth and motion vectors anyway, why not just double-buffer those resources ourselves and make good use of these otherwise dumb copies? // TODO: if PSSR needs a copy of the previous depth and motion vectors anyway, why not just double-buffer those resources ourselves and make good use of these otherwise dumb copies?
PrepareInputs(cmd, context, config, _inputColor, _inputDepth);
PrepareInputs(cmd, context, config, _inputColor, _inputDepth, _inputMotionVectors);
_dispatchParams.color = ToNativePtr(_inputColor); _dispatchParams.color = ToNativePtr(_inputColor);
_dispatchParams.depth = ToNativePtr(_inputDepth); _dispatchParams.depth = ToNativePtr(_inputDepth);
_dispatchParams.motionVectors = ToNativePtr(Shader.GetGlobalTexture(CameraMotionVectorsTexture));
_dispatchParams.motionVectors = ToNativePtr(_inputMotionVectors);
_dispatchParams.exposure = ToNativePtr(config.exposureSource switch _dispatchParams.exposure = ToNativePtr(config.exposureSource switch
{ {
Upscaling.ExposureSource.Manual when config.exposure != null => config.exposure, Upscaling.ExposureSource.Manual when config.exposure != null => config.exposure,
@ -114,7 +114,7 @@ namespace UnityEngine.Rendering.PostProcessing
var scaledRenderSize = config.GetScaledRenderSize(context.camera); var scaledRenderSize = config.GetScaledRenderSize(context.camera);
_dispatchParams.renderWidth = (uint)scaledRenderSize.x; _dispatchParams.renderWidth = (uint)scaledRenderSize.x;
_dispatchParams.renderHeight = (uint)scaledRenderSize.y; _dispatchParams.renderHeight = (uint)scaledRenderSize.y;
_dispatchParams.jitter = config.JitterOffset; // TODO: may need to scale this (should be jitter in render pixels apparently)
_dispatchParams.jitter = config.JitterOffset;
_dispatchParams.motionVectorScale = new Vector2(-scaledRenderSize.x, -scaledRenderSize.y); _dispatchParams.motionVectorScale = new Vector2(-scaledRenderSize.x, -scaledRenderSize.y);
_dispatchParams.FromCamera(context.camera); _dispatchParams.FromCamera(context.camera);
_dispatchParams.preExposure = config.preExposure; _dispatchParams.preExposure = config.preExposure;
@ -178,7 +178,7 @@ namespace UnityEngine.Rendering.PostProcessing
public Vector2 jitter; public Vector2 jitter;
public Vector2 motionVectorScale; public Vector2 motionVectorScale;
public Matrix4x4 camProjection;
public Matrix4x4 camProjectionNoJitter;
public Vector3 camForward; public Vector3 camForward;
public Vector3 camUp; public Vector3 camUp;
public Vector3 camRight; public Vector3 camRight;
@ -194,7 +194,7 @@ namespace UnityEngine.Rendering.PostProcessing
public void FromCamera(Camera cam) public void FromCamera(Camera cam)
{ {
camProjection = cam.projectionMatrix;
camProjectionNoJitter = cam.nonJitteredProjectionMatrix;
camForward = cam.transform.forward; camForward = cam.transform.forward;
camUp = cam.transform.up; camUp = cam.transform.up;
camRight = cam.transform.right; camRight = cam.transform.right;

6
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute

@ -2,11 +2,11 @@
Texture2D InColor: register(t0); Texture2D InColor: register(t0);
Texture2D<float> InDepth: register(t1); Texture2D<float> InDepth: register(t1);
//Texture2D<float2> InMotionVectors: register(t2);
Texture2D<float2> InMotionVectors: register(t2);
RWTexture2D<float4> OutColor: register(u0); RWTexture2D<float4> OutColor: register(u0);
RWTexture2D<float> OutDepth: register(u1); RWTexture2D<float> OutDepth: register(u1);
//RWTexture2D<float2> OutMotionVectors: register(u2);
RWTexture2D<float2> OutMotionVectors: register(u2);
cbuffer Params: register(b0) cbuffer Params: register(b0)
{ {
@ -23,5 +23,5 @@ void CS(uint2 GroupId: SV_GroupID, uint2 GroupThreadId: SV_GroupThreadID)
if (prepareColor) OutColor[InputPos] = InColor[InputPos]; if (prepareColor) OutColor[InputPos] = InColor[InputPos];
if (prepareDepth) OutDepth[InputPos] = InDepth[InputPos]; if (prepareDepth) OutDepth[InputPos] = InDepth[InputPos];
//if (prepareMotionVectors) OutMotionVectors[InputPos] = InMotionVectors[InputPos];
if (prepareMotionVectors) OutMotionVectors[InputPos] = InMotionVectors[InputPos];
} }
Loading…
Cancel
Save