Browse Source

Added macros to change nearest-depth and depth-clipping logic based on whether the Unity graphics API uses reversed Z or not

sgsr2_fs
Nico de Poel 1 year ago
parent
commit
19b2969e58
  1. 14
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_convert.compute
  2. 2
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_activate.compute
  3. 16
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_convert.compute
  4. 8
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/sgsr2_common.hlsl

14
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_convert.compute

@ -38,16 +38,16 @@ void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
float4 bottomLeft = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord+v12)); float4 bottomLeft = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord+v12));
float2 v14 = float2(ViewportSizeInverse.x*2.0, ViewportSizeInverse.y*2.0); float2 v14 = float2(ViewportSizeInverse.x*2.0, ViewportSizeInverse.y*2.0);
float4 bottomRight = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord+v14)); float4 bottomRight = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord+v14));
float maxC = max(max(max(topleft.y,topRight.x),bottomLeft.z),bottomRight.w);
float topleft4 = max(max(max(topleft.y,topleft.x),topleft.z),topleft.w);
float topLeftMax9 = max(bottomLeft.w,max(max(maxC,topleft4),topRight.w));
float maxC = DEPTH_NEAREST(DEPTH_NEAREST(DEPTH_NEAREST(topleft.y,topRight.x),bottomLeft.z),bottomRight.w);
float topleft4 = DEPTH_NEAREST(DEPTH_NEAREST(DEPTH_NEAREST(topleft.y,topleft.x),topleft.z),topleft.w);
float topLeftMax9 = DEPTH_NEAREST(bottomLeft.w,DEPTH_NEAREST(DEPTH_NEAREST(maxC,topleft4),topRight.w));
float depthclip = 0.0; float depthclip = 0.0;
if (maxC > 1.0e-05f)
if (DEPTH_CLIP(maxC))
{ {
float topRight4 = max(max(max(topRight.y,topRight.x),topRight.z),topRight.w);
float bottomLeft4 = max(max(max(bottomLeft.y,bottomLeft.x),bottomLeft.z),bottomLeft.w);
float bottomRight4 = max(max(max(bottomRight.y,bottomRight.x),bottomRight.z),bottomRight.w);
float topRight4 = DEPTH_NEAREST(DEPTH_NEAREST(DEPTH_NEAREST(topRight.y,topRight.x),topRight.z),topRight.w);
float bottomLeft4 = DEPTH_NEAREST(DEPTH_NEAREST(DEPTH_NEAREST(bottomLeft.y,bottomLeft.x),bottomLeft.z),bottomLeft.w);
float bottomRight4 = DEPTH_NEAREST(DEPTH_NEAREST(DEPTH_NEAREST(bottomRight.y,bottomRight.x),bottomRight.z),bottomRight.w);
float Wdepth = 0.0; float Wdepth = 0.0;
float Ksep = 1.37e-05f; float Ksep = 1.37e-05f;

2
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_activate.compute

@ -47,7 +47,7 @@ void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
#endif #endif
float depthclip = 0.0; float depthclip = 0.0;
if (depth > 1.0e-05f) {
if (DEPTH_CLIP(depth)) {
float2 Prevf_sample = PrevUV * float2(renderSize) - 0.5f; float2 Prevf_sample = PrevUV * float2(renderSize) - 0.5f;
float2 Prevfrac = Prevf_sample - floor(Prevf_sample); float2 Prevfrac = Prevf_sample - floor(Prevf_sample);
float OneMinusPrevfacx = 1.0 - Prevfrac.x; float OneMinusPrevfacx = 1.0 - Prevfrac.x;

16
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_convert.compute

@ -36,22 +36,22 @@ void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
float4 topleft = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, gatherCoord); float4 topleft = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, gatherCoord);
NearestZ = max(topleft.x, NearestZ);
NearestZ = max(topleft.y, NearestZ);
NearestZ = max(topleft.z, NearestZ);
NearestZ = max(topleft.w, NearestZ);
NearestZ = DEPTH_NEAREST(topleft.x, NearestZ);
NearestZ = DEPTH_NEAREST(topleft.y, NearestZ);
NearestZ = DEPTH_NEAREST(topleft.z, NearestZ);
NearestZ = DEPTH_NEAREST(topleft.w, NearestZ);
float2 v11 = float2(renderSizeRcp.x, 0.0); float2 v11 = float2(renderSizeRcp.x, 0.0);
float2 topRight = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord + v11)).yz; float2 topRight = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord + v11)).yz;
NearestZ = max(topRight.x, NearestZ);
NearestZ = max(topRight.y, NearestZ);
NearestZ = DEPTH_NEAREST(topRight.x, NearestZ);
NearestZ = DEPTH_NEAREST(topRight.y, NearestZ);
float2 v13 = float2(0.0, renderSizeRcp.y); float2 v13 = float2(0.0, renderSizeRcp.y);
float2 bottomLeft = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord + v13)).xy; float2 bottomLeft = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord + v13)).xy;
NearestZ = max(bottomLeft.x, NearestZ);
NearestZ = max(bottomLeft.y, NearestZ);
NearestZ = DEPTH_NEAREST(bottomLeft.x, NearestZ);
NearestZ = DEPTH_NEAREST(bottomLeft.y, NearestZ);
//refer to ue/fsr2 PostProcessFFX_FSR2ConvertVelocity.usf, and using nearest depth for dilated motion //refer to ue/fsr2 PostProcessFFX_FSR2ConvertVelocity.usf, and using nearest depth for dilated motion

8
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/sgsr2_common.hlsl

@ -1,5 +1,13 @@
#define EPSILON 1.192e-07f #define EPSILON 1.192e-07f
#ifdef UNITY_REVERSED_Z
#define DEPTH_NEAREST(a, b) max((a), (b))
#define DEPTH_CLIP(depth) ((depth) > 1.0e-05f)
#else
#define DEPTH_NEAREST(a, b) min((a), (b))
#define DEPTH_CLIP(depth) ((depth) < 1.0f - 1.0e-05f)
#endif
cbuffer Params : register(b0) cbuffer Params : register(b0)
{ {
uint2 renderSize; uint2 renderSize;

Loading…
Cancel
Save