From df58df61d6a7e05577d93e2702f2c1167fa8e683 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 28 Dec 2024 14:29:34 +0100 Subject: [PATCH] Reorganized shader code such that standard BiRP and PPV2 can share the same common code with only some light wrappers to implement the differences --- .../PostProcessing/PostProcessResources.asset | 2 +- .../SGSR2/Shaders/2_pass_fs/sgsr2_birp.shader | 49 +++++++++++++++++++ .../Shaders/2_pass_fs/sgsr2_birp.shader.meta | 3 ++ .../Shaders/2_pass_fs/sgsr2_convert.hlsl | 4 +- .../SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader | 25 ++++++++-- .../Shaders/2_pass_fs/sgsr2_upscale.hlsl | 5 +- 6 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_birp.shader create mode 100644 Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_birp.shader.meta diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset index 6041f70..954f3a9 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset @@ -115,7 +115,7 @@ MonoBehaviour: multiScaleAO: {fileID: 4800000, guid: 67f9497810829eb4791ec19e95781e51, type: 3} screenSpaceReflections: {fileID: 4800000, guid: f997a3dc9254c44459323cced085150c, type: 3} sgsr2Upscaler: - twoPassFragment: {fileID: 4800000, guid: 9e367486dadedbc4da8313a481aa8a27, type: 3} + twoPassFragment: {fileID: 4800000, guid: 59bc1035dd975f64d8141148a7088d0a, type: 3} computeShaders: autoExposure: {fileID: 7200000, guid: 34845e0ca016b7448842e965db5890a5, type: 3} exposureHistogram: {fileID: 7200000, guid: 8c2fcbdf9bc58664f89917f7b9d79501, type: 3} diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_birp.shader b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_birp.shader new file mode 100644 index 0000000..7202ee0 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_birp.shader @@ -0,0 +1,49 @@ +Shader "TND/sgsr2_2pass_fs" +{ + SubShader + { + Cull Off ZWrite Off ZTest Always + + Pass + { + Name "Convert" + + HLSLPROGRAM + #pragma vertex vert_img + #pragma fragment frag_convert + #pragma target 4.5 + #pragma enable_d3d11_debug_symbols + + #include "../sgsr2_birp.hlsl" + #include "sgsr2_convert.hlsl" + + void frag_convert(v2f_img i, out float4 MotionDepthClipAlphaBuffer: SV_Target) + { + sgsr2_convert(i.uv, MotionDepthClipAlphaBuffer); + } + + ENDHLSL + } + + Pass + { + Name "Upscale" + + HLSLPROGRAM + #pragma vertex vert_img + #pragma fragment frag_upscale + #pragma target 4.5 + #pragma enable_d3d11_debug_symbols + + #include "../sgsr2_birp.hlsl" + #include "sgsr2_upscale.hlsl" + + void frag_upscale(v2f_img i, out half4 OutputColor: SV_Target) + { + sgsr2_upscale(i.uv, OutputColor); + } + + ENDHLSL + } + } +} diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_birp.shader.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_birp.shader.meta new file mode 100644 index 0000000..6098da7 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_birp.shader.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4451c8b25af942ccaa8d6d0bb46a8e60 +timeCreated: 1735392260 \ No newline at end of file diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_convert.hlsl b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_convert.hlsl index e3367ea..a4b9e7b 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_convert.hlsl +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_convert.hlsl @@ -1,4 +1,3 @@ -#include "../sgsr2_birp.hlsl" #include "../sgsr2_common.hlsl" //============================================================================================================ @@ -18,9 +17,8 @@ TYPED_TEXTURE2D_X(half2, _CameraMotionVectorsTexture); #define InputDepth _CameraDepthTexture #define InputVelocity _CameraMotionVectorsTexture -void sgsr2_convert(VaryingsDefault i, out float4 MotionDepthClipAlphaBuffer: SV_Target) +void sgsr2_convert(const half2 texCoord, out float4 MotionDepthClipAlphaBuffer) { - const half2 texCoord = i.texcoord; uint2 InputPos = uint2(texCoord * renderSize); float2 gatherCoord = texCoord - 0.5f * renderSizeRcp; diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader index 7e7f176..bf4ecc7 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader @@ -4,35 +4,52 @@ Shader "TND/PPV2/sgsr2_2pass_fs" { Cull Off ZWrite Off ZTest Always - Pass // Convert + Pass { Name "Convert" HLSLPROGRAM #pragma vertex VertDefault - #pragma fragment sgsr2_convert + #pragma fragment FragConvert #pragma target 4.5 #pragma enable_d3d11_debug_symbols #define UNITY_CG_INCLUDED #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl" + #undef EPSILON + #include "../sgsr2_birp.hlsl" #include "sgsr2_convert.hlsl" + + void FragConvert(VaryingsDefault i, out float4 MotionDepthClipAlphaBuffer: SV_Target) + { + sgsr2_convert(i.texcoord, MotionDepthClipAlphaBuffer); + } + ENDHLSL } - Pass // Upscale + Pass { Name "Upscale" HLSLPROGRAM #pragma vertex VertDefault - #pragma fragment sgsr2_upscale + #pragma fragment FragUpscale #pragma target 4.5 #pragma enable_d3d11_debug_symbols #define UNITY_CG_INCLUDED #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl" + #undef EPSILON + #include "../sgsr2_birp.hlsl" #include "sgsr2_upscale.hlsl" + + void FragUpscale(VaryingsDefault i, out half4 OutputColor: SV_Target0, out half4 HistoryOutput: SV_Target1) + { + sgsr2_upscale(i.texcoord, OutputColor); + HistoryOutput = OutputColor; + } + ENDHLSL } } diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_upscale.hlsl b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_upscale.hlsl index 7f8183d..62904ac 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_upscale.hlsl +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_upscale.hlsl @@ -1,4 +1,3 @@ -#include "../sgsr2_birp.hlsl" #include "../sgsr2_common.hlsl" //============================================================================================================ @@ -21,9 +20,8 @@ SamplerState samplerPrevOutput; SamplerState samplerMotionDepthClipAlphaBuffer; SamplerState samplerInputColor; -void sgsr2_upscale(VaryingsDefault i, out half4 Output: SV_Target0, out half4 HistoryOutput: SV_Target1) +void sgsr2_upscale(const half2 texCoord, out half4 Output) { - const half2 texCoord = i.texcoord; half Biasmax_viewportXScale = scaleRatio.x; half scalefactor = scaleRatio.y; @@ -262,5 +260,4 @@ void sgsr2_upscale(VaryingsDefault i, out half4 Output: SV_Target0, out half4 Hi Upsampledcw.xyz = lerp(HistoryColor, Upsampledcw.xyz, alpha); Output = half4(Upsampledcw.xyz, 0.0); - HistoryOutput = Output; }