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 abbf9e8..e3367ea 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 @@ -18,9 +18,9 @@ TYPED_TEXTURE2D_X(half2, _CameraMotionVectorsTexture); #define InputDepth _CameraDepthTexture #define InputVelocity _CameraMotionVectorsTexture -void sgsr2_convert(v2f_img i, out float4 MotionDepthClipAlphaBuffer: SV_Target) +void sgsr2_convert(VaryingsDefault i, out float4 MotionDepthClipAlphaBuffer: SV_Target) { - const half2 texCoord = i.uv; + 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.shader b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader similarity index 64% rename from Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2.shader rename to Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader index 84b89ab..7e7f176 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2.shader +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader @@ -1,4 +1,4 @@ -Shader "TND/sgsr2_2pass_fs" +Shader "TND/PPV2/sgsr2_2pass_fs" { SubShader { @@ -9,11 +9,13 @@ Shader "TND/sgsr2_2pass_fs" Name "Convert" HLSLPROGRAM - #pragma vertex vert_img + #pragma vertex VertDefault #pragma fragment sgsr2_convert #pragma target 4.5 #pragma enable_d3d11_debug_symbols + #define UNITY_CG_INCLUDED + #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl" #include "sgsr2_convert.hlsl" ENDHLSL } @@ -23,11 +25,13 @@ Shader "TND/sgsr2_2pass_fs" Name "Upscale" HLSLPROGRAM - #pragma vertex vert_img + #pragma vertex VertDefault #pragma fragment sgsr2_upscale #pragma target 4.5 #pragma enable_d3d11_debug_symbols + #define UNITY_CG_INCLUDED + #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl" #include "sgsr2_upscale.hlsl" ENDHLSL } diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2.shader.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader.meta similarity index 80% rename from Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2.shader.meta rename to Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader.meta index 435c493..bad8ad4 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2.shader.meta +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_fs/sgsr2_ppv2.shader.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9e367486dadedbc4da8313a481aa8a27 +guid: 59bc1035dd975f64d8141148a7088d0a ShaderImporter: externalObjects: {} defaultTextures: [] 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 06da4d7..7f8183d 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 @@ -21,9 +21,9 @@ SamplerState samplerPrevOutput; SamplerState samplerMotionDepthClipAlphaBuffer; SamplerState samplerInputColor; -void sgsr2_upscale(v2f_img i, out half4 Output: SV_Target) +void sgsr2_upscale(VaryingsDefault i, out half4 Output: SV_Target0, out half4 HistoryOutput: SV_Target1) { - const half2 texCoord = i.uv; + const half2 texCoord = i.texcoord; half Biasmax_viewportXScale = scaleRatio.x; half scalefactor = scaleRatio.y; @@ -262,4 +262,5 @@ void sgsr2_upscale(v2f_img i, out half4 Output: SV_Target) Upsampledcw.xyz = lerp(HistoryColor, Upsampledcw.xyz, alpha); Output = half4(Upsampledcw.xyz, 0.0); + HistoryOutput = Output; } diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler.cs index c386d59..6c9ef84 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler.cs @@ -70,7 +70,7 @@ namespace UnityEngine.Rendering.PostProcessing parms.cameraFovAngleHor = Mathf.Tan(context.camera.fieldOfView * Mathf.Deg2Rad * 0.5f) * parms.renderSize.x * parms.renderSizeRcp.y; parms.cameraNear = context.camera.nearClipPlane; parms.minLerpContribution = 0f; - parms.scaleRatio = new Vector2(parms.renderSize.x * parms.displaySizeRcp.x, parms.renderSize.y * parms.displaySizeRcp.y); + parms.scaleRatio = new Vector2(parms.displaySize.x * parms.renderSizeRcp.x, parms.displaySize.y * parms.renderSizeRcp.y); parms.bSameCamera = isCameraStill ? 1u : 0u; parms.reset = config.Reset ? 1u : 0u; _paramsBuffer.UpdateBufferData(cmd); diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler_2PassFS.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler_2PassFS.cs index 2f67b19..df39c3f 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler_2PassFS.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler_2PassFS.cs @@ -7,6 +7,7 @@ namespace UnityEngine.Rendering.PostProcessing protected override string VariantName => "SGSR2 2-Pass Fragment"; private Material _material; + private readonly RenderTargetIdentifier[] _mrt = new RenderTargetIdentifier[2]; public override void CreateContext(PostProcessRenderContext context, Upscaling config) { @@ -26,14 +27,19 @@ namespace UnityEngine.Rendering.PostProcessing { uint frameIndex = _frameCount % 2; + // TODO: try using a PropertySheet here again, now that PPV2 is functional cmd.SetGlobalTexture("InputColor", context.source); cmd.SetGlobalTexture("MotionDepthClipAlphaBuffer", _motionDepthClipAlpha); cmd.SetGlobalTexture("PrevOutput", _upscaleHistory[frameIndex ^ 1]); cmd.SetGlobalConstantBuffer(_paramsBuffer, "cbSGSR2", 0, Marshal.SizeOf()); + + cmd.SetRenderTarget(_motionDepthClipAlpha, context.source); + cmd.DrawMesh(RuntimeUtilities.fullscreenTriangle, Matrix4x4.identity, _material, 0, 0); - cmd.Blit(BuiltinRenderTextureType.None, _motionDepthClipAlpha, _material, 0); - cmd.Blit(BuiltinRenderTextureType.None, _upscaleHistory[frameIndex], _material, 1); - cmd.Blit(_upscaleHistory[frameIndex], context.destination); + _mrt[0] = context.destination; + _mrt[1] = _upscaleHistory[frameIndex]; + cmd.SetRenderTarget(_mrt, context.destination); + cmd.DrawMesh(RuntimeUtilities.fullscreenTriangle, Matrix4x4.identity, _material, 0, 1); } } }