Browse Source

Moved a bunch of common definitions and functions into a separate file

sgsr2_fs
Nico de Poel 1 year ago
parent
commit
8d6036c91c
  1. 19
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_convert.compute
  2. 40
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_upscale.compute
  3. 41
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_activate.compute
  4. 26
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_convert.compute
  5. 40
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_upscale.compute
  6. 55
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/sgsr2_common.hlsl
  7. 3
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/sgsr2_common.hlsl.meta

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

@ -1,5 +1,6 @@
#pragma kernel CS
#include "../sgsr2_birp.hlsl"
#include "../sgsr2_common.hlsl"
//============================================================================================================
//
@ -15,23 +16,6 @@ TYPED_TEXTURE2D_X(float2, InputVelocity) : register(t2);
RW_TEXTURE2D_X(half4, MotionDepthClipAlphaBuffer) : register(u0);
RW_TEXTURE2D_X(uint, YCoCgColor) : register(u1);
cbuffer Params : register(b0)
{
uint2 renderSize;
uint2 displaySize;
float2 renderSizeRcp;
float2 displaySizeRcp;
float2 jitterOffset;
float2 padding1;
float4 clipToPrevClip[4];
float preExposure;
float cameraFovAngleHor;
float cameraNear;
float MinLerpContribution;
uint bSameCamera;
uint reset;
};
[numthreads(8, 8, 1)]
void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
{
@ -72,7 +56,6 @@ void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
float Ksep_Kfov_diagonal = Ksep * Kfov * diagonal_length;
float Depthsep = Ksep_Kfov_diagonal * (1.0 - maxC);
float EPSILON = 1.19e-07f;
Wdepth += clamp((Depthsep / (abs(maxC - topleft4) + EPSILON)), 0.0, 1.0);
Wdepth += clamp((Depthsep / (abs(maxC - topRight4) + EPSILON)), 0.0, 1.0);
Wdepth += clamp((Depthsep / (abs(maxC - bottomLeft4) + EPSILON)), 0.0, 1.0);

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

@ -1,5 +1,6 @@
#pragma kernel CS
#include "../sgsr2_birp.hlsl"
#include "../sgsr2_common.hlsl"
//============================================================================================================
//
@ -9,50 +10,12 @@
//
//============================================================================================================
float FastLanczos(float base)
{
float y = base - 1.0f;
float y2 = y * y;
float y_temp = 0.75f * y + y2;
return y_temp * y2;
}
float3 DecodeColor(uint sample32)
{
uint x11 = sample32 >> 21u;
uint y11 = sample32 & (2047u << 10u);
uint z10 = sample32 & 1023u;
float3 samplecolor;
samplecolor.x = (float(x11) * (1.0 / 2047.5));
samplecolor.y = (float(y11) * (4.76953602e-7)) - 0.5;
samplecolor.z = (float(z10) * (1.0 / 1023.5)) - 0.5;
return samplecolor;
}
TEXTURE2D_X(PrevHistoryOutput) : register(t0);
TEXTURE2D_X(MotionDepthClipAlphaBuffer) : register(t1);
TYPED_TEXTURE2D_X(uint, YCoCgColor) : register(t2);
RW_TEXTURE2D_X(half4, SceneColorOutput) : register(u0);
RW_TEXTURE2D_X(half4, HistoryOutput) : register(u1);
cbuffer Params : register(b0)
{
uint2 renderSize;
uint2 displaySize;
float2 renderSizeRcp;
float2 displaySizeRcp;
float2 jitterOffset;
float2 padding1;
float4 clipToPrevClip[4];
float preExposure;
float cameraFovAngleHor;
float cameraNear;
float MinLerpContribution;
uint bSameCamera;
uint reset;
};
[numthreads(8, 8, 1)]
void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
{
@ -290,7 +253,6 @@ void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
baseupdate = min(baseupdate, lerp(baseupdate, Upsampledcw.w, clamp(motion_viewport_len *0.05f, 0.0, 1.0)));
float basealpha = baseupdate;
const float EPSILON = 1.192e-07f;
float boxscale = max(depthfactor, clamp(motion_viewport_len * 0.05f, 0.0, 1.0));
float boxsize = lerp(scalefactor, 1.0f, boxscale);
float3 sboxvar = rectboxvar * boxsize;

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

@ -1,7 +1,6 @@
#pragma kernel CS
#include "../sgsr2_birp.hlsl"
// TODO: what about REQUEST_NDC_Y_UP? Might be graphics API-dependent, look at Unity's shader includes.
#include "../sgsr2_common.hlsl"
//============================================================================================================
//
@ -11,46 +10,12 @@
//
//============================================================================================================
#define EPSILON 1.19e-07f
float DecodeColorY(uint sample32)
{
uint x11 = sample32 >> 21u;
return float(x11) * (1.0 / 2047.5);
}
uint packHalf2x16(float2 value)
{
return f32tof16(value.x) | (f32tof16(value.y) << 16);
}
float2 unpackHalf2x16(uint x)
{
return f16tof32(uint2(x & 0xFFFF, x >> 16));
}
TYPED_TEXTURE2D_X(uint, PrevLumaHistory) : register(t0);
TYPED_TEXTURE2D_X(half4, MotionDepthAlphaBuffer) : register(t1);
TYPED_TEXTURE2D_X(uint, YCoCgColor) : register(t2);
RW_TEXTURE2D_X(half4, MotionDepthClipAlphaBuffer) : register(u0);
RW_TEXTURE2D_X(uint, LumaHistory) : register(u1);
cbuffer Params : register(b0)
{
uint2 renderSize;
uint2 displaySize;
float2 ViewportSizeInverse;
float2 displaySizeRcp;
float2 jitterOffset;
float2 padding1;
float4 clipToPrevClip[4];
float preExposure;
float cameraFovAngleHor;
float cameraNear;
float MinLerpContribution;
uint bSameCamera;
uint reset;
};
[numthreads(8, 8, 1)]
void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
{
@ -65,8 +30,8 @@ void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
uint2 InputPos = gl_GlobalInvocationID.xy;
float2 ViewportUV = (float2(gl_GlobalInvocationID.xy) + 0.5f) * ViewportSizeInverse;
float2 gatherCoord = ViewportUV + 0.5f * ViewportSizeInverse;
float2 ViewportUV = (float2(gl_GlobalInvocationID.xy) + 0.5f) * renderSizeRcp;
float2 gatherCoord = ViewportUV + 0.5f * renderSizeRcp;
uint luma_reference32 = GATHER_RED_TEXTURE2D_X(YCoCgColor, S_POINT_CLAMP, gatherCoord).w;
float luma_reference = DecodeColorY(luma_reference32);

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

@ -1,5 +1,6 @@
#pragma kernel CS
#include "../sgsr2_birp.hlsl"
#include "../sgsr2_common.hlsl"
//============================================================================================================
//
@ -16,23 +17,6 @@ TYPED_TEXTURE2D_X(float2, InputVelocity) : register(t3);
RW_TEXTURE2D_X(half4, MotionDepthAlphaBuffer) : register(u0);
RW_TEXTURE2D_X(uint, YCoCgColor) : register(u1);
cbuffer Params : register(b0)
{
uint2 renderSize;
uint2 displaySize;
float2 ViewportSizeInverse;
float2 displaySizeRcp;
float2 jitterOffset;
float2 padding1;
float4 clipToPrevClip[4];
float preExposure;
float cameraFovAngleHor;
float cameraNear;
float MinLerpContribution;
uint bSameCamera;
uint reset;
};
[numthreads(8, 8, 1)]
void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
{
@ -41,8 +25,8 @@ void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
half h0 = preExposure;
uint2 InputPos = gl_GlobalInvocationID.xy;
float2 gatherCoord = float2(gl_GlobalInvocationID.xy) * ViewportSizeInverse;
float2 ViewportUV = gatherCoord + 0.5f * ViewportSizeInverse;
float2 gatherCoord = float2(gl_GlobalInvocationID.xy) * renderSizeRcp;
float2 ViewportUV = gatherCoord + 0.5f * renderSizeRcp;
//derived from ffx_fsr2_reconstruct_dilated_velocity_and_previous_depth.h
//FindNearestDepth
@ -57,13 +41,13 @@ void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
NearestZ = max(topleft.z, NearestZ);
NearestZ = max(topleft.w, NearestZ);
float2 v11 = float2(ViewportSizeInverse.x, 0.0);
float2 v11 = float2(renderSizeRcp.x, 0.0);
float2 topRight = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord + v11)).yz;
NearestZ = max(topRight.x, NearestZ);
NearestZ = max(topRight.y, NearestZ);
float2 v13 = float2(0.0, ViewportSizeInverse.y);
float2 v13 = float2(0.0, renderSizeRcp.y);
float2 bottomLeft = GATHER_RED_TEXTURE2D_X(InputDepth, S_POINT_CLAMP, (gatherCoord + v13)).xy;
NearestZ = max(bottomLeft.x, NearestZ);

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

@ -1,5 +1,6 @@
#pragma kernel CS
#include "../sgsr2_birp.hlsl"
#include "../sgsr2_common.hlsl"
//============================================================================================================
//
@ -9,50 +10,12 @@
//
//============================================================================================================
float FastLanczos(float base)
{
float y = base - 1.0f;
float y2 = y * y;
float y_temp = 0.75f * y + y2;
return y_temp * y2;
}
float3 DecodeColor(uint sample32)
{
uint x11 = sample32 >> 21u;
uint y11 = sample32 & (2047u << 10u);
uint z10 = sample32 & 1023u;
float3 samplecolor;
samplecolor.x = (float(x11) * (1.0 / 2047.5));
samplecolor.y = (float(y11) * (4.76953602e-7)) - 0.5;
samplecolor.z = (float(z10) * (1.0 / 1023.5)) - 0.5;
return samplecolor;
}
TEXTURE2D_X(PrevHistoryOutput) : register(t0);
TEXTURE2D_X(MotionDepthClipAlphaBuffer) : register(t1);
TYPED_TEXTURE2D_X(uint, YCoCgColor) : register(t2);
RW_TEXTURE2D_X(half4, SceneColorOutput) : register(u0);
RW_TEXTURE2D_X(half4, HistoryOutput) : register(u1);
cbuffer Params : register(b0)
{
uint2 renderSize;
uint2 displaySize;
float2 renderSizeRcp;
float2 displaySizeRcp;
float2 jitterOffset;
float2 padding1;
float4 clipToPrevClip[4];
float preExposure;
float cameraFovAngleHor;
float cameraNear;
float MinLerpContribution;
uint bSameCamera;
uint reset;
};
[numthreads(8, 8, 1)]
void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
{
@ -277,7 +240,6 @@ void CS(uint3 gl_GlobalInvocationID : SV_DispatchThreadID)
baseupdate = min(baseupdate, lerp(baseupdate, Upsampledcw.w, clamp(motion_viewport_len *0.05f, 0.0, 1.0)));
float basealpha = baseupdate;
const float EPSILON = 1.192e-07f;
float boxscale = max(depthfactor, clamp(motion_viewport_len * 0.05f, 0.0, 1.0));
float boxsize = lerp(scalefactor, 1.0f, boxscale);
float3 sboxvar = rectboxvar * boxsize;

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

@ -0,0 +1,55 @@
#define EPSILON 1.192e-07f
cbuffer Params : register(b0)
{
uint2 renderSize;
uint2 displaySize;
float2 renderSizeRcp;
float2 displaySizeRcp;
float2 jitterOffset;
float2 padding1;
float4 clipToPrevClip[4];
float preExposure;
float cameraFovAngleHor;
float cameraNear;
float MinLerpContribution;
uint bSameCamera;
uint reset;
};
float FastLanczos(float base)
{
float y = base - 1.0f;
float y2 = y * y;
float y_temp = 0.75f * y + y2;
return y_temp * y2;
}
float3 DecodeColor(uint sample32)
{
uint x11 = sample32 >> 21u;
uint y11 = sample32 & (2047u << 10u);
uint z10 = sample32 & 1023u;
float3 samplecolor;
samplecolor.x = (float(x11) * (1.0 / 2047.5));
samplecolor.y = (float(y11) * (4.76953602e-7)) - 0.5;
samplecolor.z = (float(z10) * (1.0 / 1023.5)) - 0.5;
return samplecolor;
}
float DecodeColorY(uint sample32)
{
uint x11 = sample32 >> 21u;
return float(x11) * (1.0 / 2047.5);
}
uint packHalf2x16(float2 value)
{
return f32tof16(value.x) | (f32tof16(value.y) << 16);
}
float2 unpackHalf2x16(uint x)
{
return f16tof32(uint2(x & 0xFFFF, x >> 16));
}

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

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bff676b8468748078a48f9d10bb7eabd
timeCreated: 1734795662
Loading…
Cancel
Save