Browse Source

Consolidated SGSR2 shaders into single .compute files as there's not much point in using includes, and grouped them together into a 3-pass folder. This will make it easier to add the other variants later.

sgsr2_fs
Nico de Poel 1 year ago
parent
commit
708e4308c5
  1. 2
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs.meta
  2. 16
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_activate.compute
  3. 0
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_activate.compute.meta
  4. 12
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_convert.compute
  5. 0
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_convert.compute.meta
  6. 38
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_upscale.compute
  7. 0
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_upscale.compute.meta
  8. 3
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/sgsr2_activate.compute
  9. 3
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/sgsr2_convert.compute
  10. 3
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/sgsr2_upscale.compute
  11. 7
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders/sgsr2_activate.hlsl.meta
  12. 7
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders/sgsr2_convert.hlsl.meta
  13. 7
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders/sgsr2_upscale.hlsl.meta

2
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders.meta → Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 81bb130e0ef32fa4fb623a65d2f2116e
guid: 30c2581cbd096d349bf552c4b0886d84
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

16
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders/sgsr2_activate.hlsl → Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_activate.compute

@ -1,3 +1,7 @@
#pragma kernel CS
// TODO: what about REQUEST_NDC_Y_UP? Might be graphics API-dependent, look at Unity's shader includes.
//============================================================================================================ //============================================================================================================
// //
// //
@ -9,8 +13,8 @@
#define EPSILON 1.19e-07f #define EPSILON 1.19e-07f
float DecodeColorY(uint sample32) float DecodeColorY(uint sample32)
{ {
uint x11 = sample32 >> 21u;
return float(x11) * (1.0 / 2047.5);
uint x11 = sample32 >> 21u;
return float(x11) * (1.0 / 2047.5);
} }
uint packHalf2x16(float2 value) uint packHalf2x16(float2 value)
@ -66,10 +70,10 @@ void CS(uint3 globalInvocationID : SV_DispatchThreadID)
uint luma_reference32 = YCoCgColor.GatherRed(s_PointClamp, gatherCoord).w; uint luma_reference32 = YCoCgColor.GatherRed(s_PointClamp, gatherCoord).w;
float luma_reference = DecodeColorY(luma_reference32); float luma_reference = DecodeColorY(luma_reference32);
float4 mda = MotionDepthAlphaBuffer[globalInvocationID.xy].xyzw; //motion depth alpha
float depth = mda.z;
float alphamask = mda.w;
float2 motion = mda.xy;
float4 mda = MotionDepthAlphaBuffer[globalInvocationID.xy].xyzw; //motion depth alpha
float depth = mda.z;
float alphamask = mda.w;
float2 motion = mda.xy;
#ifdef REQUEST_NDC_Y_UP #ifdef REQUEST_NDC_Y_UP
float2 PrevUV = float2(-0.5f * motion.x + ViewportUV.x, 0.5f * motion.y + ViewportUV.y); float2 PrevUV = float2(-0.5f * motion.x + ViewportUV.x, 0.5f * motion.y + ViewportUV.y);

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

12
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders/sgsr2_convert.hlsl → Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_convert.compute

@ -1,3 +1,5 @@
#pragma kernel CS
//============================================================================================================ //============================================================================================================
// //
// //
@ -57,15 +59,15 @@ void CS(uint3 globalInvocationID : SV_DispatchThreadID)
float4 topleft = InputDepth.GatherRed(s_PointClamp, gatherCoord); float4 topleft = InputDepth.GatherRed(s_PointClamp, gatherCoord);
NearestZ = max(topleft.x, NearestZ); NearestZ = max(topleft.x, NearestZ);
NearestZ = max(topleft.y, NearestZ);
NearestZ = max(topleft.z, NearestZ);
NearestZ = max(topleft.w, NearestZ);
NearestZ = max(topleft.y, NearestZ);
NearestZ = max(topleft.z, NearestZ);
NearestZ = max(topleft.w, NearestZ);
float2 v11 = float2(ViewportSizeInverse.x, 0.0); float2 v11 = float2(ViewportSizeInverse.x, 0.0);
float2 topRight = InputDepth.GatherRed(s_PointClamp, (gatherCoord + v11)).yz; float2 topRight = InputDepth.GatherRed(s_PointClamp, (gatherCoord + v11)).yz;
NearestZ = max(topRight.x, NearestZ);
NearestZ = max(topRight.y, NearestZ);
NearestZ = max(topRight.x, NearestZ);
NearestZ = max(topRight.y, NearestZ);
float2 v13 = float2(0.0, ViewportSizeInverse.y); float2 v13 = float2(0.0, ViewportSizeInverse.y);
float2 bottomLeft = InputDepth.GatherRed(s_PointClamp, (gatherCoord + v13)).xy; float2 bottomLeft = InputDepth.GatherRed(s_PointClamp, (gatherCoord + v13)).xy;

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

38
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders/sgsr2_upscale.hlsl → Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/3_pass_cs/sgsr2_upscale.compute

@ -1,3 +1,5 @@
#pragma kernel CS
//============================================================================================================ //============================================================================================================
// //
// //
@ -8,23 +10,23 @@
float FastLanczos(float base) float FastLanczos(float base)
{ {
float y = base - 1.0f;
float y2 = y * y;
float y_temp = 0.75f * y + y2;
return y_temp * y2;
float y = base - 1.0f;
float y2 = y * y;
float y_temp = 0.75f * y + y2;
return y_temp * y2;
} }
float3 DecodeColor(uint sample32) 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;
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;
return samplecolor;
} }
Texture2D PrevHistoryOutput : register(t0); Texture2D PrevHistoryOutput : register(t0);
@ -266,9 +268,9 @@ void CS(uint3 globalInvocationID : SV_DispatchThreadID)
Upsampledcw.xyz = clamp(Upsampledcw.xyz / Upsampledcw.w, rectboxmin-0.05f, rectboxmax+0.05f); Upsampledcw.xyz = clamp(Upsampledcw.xyz / Upsampledcw.w, rectboxmin-0.05f, rectboxmax+0.05f);
Upsampledcw.w = Upsampledcw.w * (1.0f / 3.0f) ; Upsampledcw.w = Upsampledcw.w * (1.0f / 3.0f) ;
float tcontribute = history_value * clamp(rectboxvar.x * 10.0f, 0.0, 1.0);
float OneMinusWfactor = 1.0f - Wfactor;
tcontribute = tcontribute * OneMinusWfactor;
float tcontribute = history_value * clamp(rectboxvar.x * 10.0f, 0.0, 1.0);
float OneMinusWfactor = 1.0f - Wfactor;
tcontribute = tcontribute * OneMinusWfactor;
float baseupdate = OneMinusWfactor - OneMinusWfactor * depthfactor; float baseupdate = OneMinusWfactor - OneMinusWfactor * depthfactor;
baseupdate = min(baseupdate, lerp(baseupdate, Upsampledcw.w *10.0f, clamp(10.0f* motion_viewport_len, 0.0, 1.0))); baseupdate = min(baseupdate, lerp(baseupdate, Upsampledcw.w *10.0f, clamp(10.0f* motion_viewport_len, 0.0, 1.0)));
@ -285,9 +287,9 @@ void CS(uint3 globalInvocationID : SV_DispatchThreadID)
rectboxmin = max(rectboxmin, boxmin); rectboxmin = max(rectboxmin, boxmin);
float3 clampedcolor = clamp(HistoryColor, rectboxmin, rectboxmax); float3 clampedcolor = clamp(HistoryColor, rectboxmin, rectboxmax);
float lerpcontribution = (any(rectboxmin > HistoryColor) || any(HistoryColor > rectboxmax)) ? tcontribute : 1.0f;
lerpcontribution = lerpcontribution - lerpcontribution * sqrt(alphamask);
HistoryColor = lerp(clampedcolor, HistoryColor, clamp(lerpcontribution, 0.0, 1.0));
float lerpcontribution = (any(rectboxmin > HistoryColor) || any(HistoryColor > rectboxmax)) ? tcontribute : 1.0f;
lerpcontribution = lerpcontribution - lerpcontribution * sqrt(alphamask);
HistoryColor = lerp(clampedcolor, HistoryColor, clamp(lerpcontribution, 0.0, 1.0));
float basemin = min(basealpha, 0.1f); float basemin = min(basealpha, 0.1f);
basealpha = lerp(basemin, basealpha, clamp(lerpcontribution, 0.0, 1.0)); basealpha = lerp(basemin, basealpha, clamp(lerpcontribution, 0.0, 1.0));

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

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

@ -1,3 +0,0 @@
#pragma kernel CS
#include "shaders/sgsr2_activate.hlsl"

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

@ -1,3 +0,0 @@
#pragma kernel CS
#include "shaders/sgsr2_convert.hlsl"

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

@ -1,3 +0,0 @@
#pragma kernel CS
#include "shaders/sgsr2_upscale.hlsl"

7
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders/sgsr2_activate.hlsl.meta

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 503a58dfbaf241c4cbabb2b264d66f96
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders/sgsr2_convert.hlsl.meta

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: d980c2a95e08a894d96b558154687e24
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/shaders/sgsr2_upscale.hlsl.meta

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 5cde6f90c795fb841a38f37495375e6e
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save