diff --git a/Assets/Settings/Mobile/Mobile_High.asset b/Assets/Settings/Mobile/Mobile_High.asset index 5bbacbc..4605d3b 100644 --- a/Assets/Settings/Mobile/Mobile_High.asset +++ b/Assets/Settings/Mobile/Mobile_High.asset @@ -28,7 +28,7 @@ MonoBehaviour: m_SupportsHDR: 1 m_HDRColorBufferPrecision: 0 m_MSAA: 1 - m_RenderScale: 1 + m_RenderScale: 0.6666667 m_UpscalingFilter: 1 m_FsrOverrideSharpness: 1 m_FsrSharpness: 1 diff --git a/Assets/Settings/Mobile/Mobile_High_Renderer.asset b/Assets/Settings/Mobile/Mobile_High_Renderer.asset index 98fb638..254c661 100644 --- a/Assets/Settings/Mobile/Mobile_High_Renderer.asset +++ b/Assets/Settings/Mobile/Mobile_High_Renderer.asset @@ -45,7 +45,7 @@ MonoBehaviour: m_Name: FSR m_EditorClassIdentifier: m_Active: 1 - Quality: 0 + Quality: 1 v1setting: EasuCompute: {fileID: 7200000, guid: 787b0c165dad9074e9489817de945916, type: 3} RacsCompute: {fileID: 7200000, guid: a50f730ab549f794cbe91f005703e208, type: 3} @@ -97,13 +97,13 @@ MonoBehaviour: PerformSharpenPass: 1 Sharpness: 0.5 VelocityFactor: 1 - AutoGenerateTransparencyAndComposition: 1 + AutoGenerateTransparencyAndComposition: 0 GenerateTransparencyAndCompositionParameters: autoTcThreshold: 0.05 autoTcScale: 1 autoReactiveScale: 5 autoReactiveMax: 0.9 - AutoGenerateReactiveMask: 1 + AutoGenerateReactiveMask: 0 GenerateReactiveParameters: scale: 0.5 cutoffThreshold: 0.2 @@ -138,7 +138,7 @@ MonoBehaviour: m_Name: GSR m_EditorClassIdentifier: m_Active: 0 - quality: 1 + quality: 3 v1settings: EnableEdgeDirection: 1 Mode: 1 @@ -147,11 +147,12 @@ MonoBehaviour: GSRV1Material: {fileID: 2100000, guid: d57e64d5723127243b429034bed82c7d, type: 2} v2settings: UseCompute2Pass: 1 + UseCompute3Pass: 1 GSRV2Material: {fileID: 2100000, guid: faa906817c0647f42a0cec70faeb91c1, type: 2} - GSRV2ComputeShader: {fileID: 7200000, guid: 9a4e6ff1f9a33fa4ea1e9744e313e2fd, type: 3} + GSR2psComputeShader: {fileID: 7200000, guid: 9a4e6ff1f9a33fa4ea1e9744e313e2fd, type: 3} + GSR3psComputeShader: {fileID: 7200000, guid: e1d5384c19bf4498b85b157bf0642a27, type: 3} FiveSample: 0 - Exposure_co_rcp: 0.55 - MipMapBias: -0.04 + Exposure_co_rcp: 3 --- !u!114 &-2390300670611609275 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/DLSS.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/DLSS.cs index 154e864..d1dea0e 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/DLSS.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/DLSS.cs @@ -1,3 +1,4 @@ +using FidelityFX.FSR2; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; @@ -15,8 +16,6 @@ namespace X.Rendering.Feature private float sharpness; [SerializeField, Range(0, 2)] private float preExposure; - [SerializeField, Range(-2, 2)] - private float mipMapBias; private ProfilingSampler profiler; @@ -166,7 +165,7 @@ namespace X.Rendering.Feature }; SuperResolutionParamSets.Instance.Set("NeedJitter", true); - SuperResolutionParamSets.Instance.Set("MipmapBias", mipMapBias); + SuperResolutionParamSets.Instance.Set("MipmapBias", Fsr2.GetMipmapBiasOffset(source.referenceSize.x, (int)outputWidth)); var jitter = TemporalAA.CurrentJitter; diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/FSR.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/FSR.cs index 73c1ab9..51a3925 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/FSR.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/FSR.cs @@ -83,7 +83,6 @@ namespace X.Rendering.Feature public GenerateTcrParameters GenerateTransparencyAndCompositionParameters = new GenerateTcrParameters(); public bool AutoGenerateReactiveMask; public GenerateReactiveParameters GenerateReactiveParameters = new GenerateReactiveParameters(); - public bool AutoExposureSource; } diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/GSR.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/GSR.cs index 4405b2b..b1274a2 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/GSR.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/GSR.cs @@ -1,3 +1,5 @@ +using FidelityFX.FSR2; +using Intel; using System; using Unity.Mathematics; using UnityEngine; @@ -34,8 +36,6 @@ namespace X.Rendering.Feature public int Mode = 1; [SerializeField, Range(0.5f, 2.5f)] public float Sharp = 2; - [SerializeField, Range(-5f, 2.5f)] - public float MipMapBias = 0; [SerializeField] public Material GSRV1Material; } @@ -49,15 +49,20 @@ namespace X.Rendering.Feature [SerializeField] public bool UseCompute2Pass = false; [SerializeField] + public bool UseCompute3Pass = false; + [SerializeField] public Material GSRV2Material; [SerializeField] - public ComputeShader GSRV2ComputeShader; + public ComputeShader GSR2psComputeShader; + [SerializeField] + public ComputeShader GSR3psComputeShader; [SerializeField] public bool FiveSample = false; [SerializeField] public float Exposure_co_rcp = 1; - [SerializeField, Range(-5f, 2.5f)] - public float MipMapBias = 0; + + internal bool useCompute = false; + } [SerializeField] private V2Setting v2settings; @@ -70,14 +75,6 @@ namespace X.Rendering.Feature public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) { - //if (useGSR1) - //{ - // renderer.EnqueuePass(gsr1); - //} - //else - //{ - // renderer.EnqueuePass(gsr2); - //} } public override void Create() @@ -149,6 +146,7 @@ namespace X.Rendering.Feature { SetActive(true); useGSR1 = false; + v2settings.useCompute = resolution == ESuperResolution.GSR2_COMPUTE; } break; default: @@ -208,7 +206,7 @@ namespace X.Rendering.Feature cameraData.imageScalingMode = ImageScalingMode.None; cameraData.upscalingFilter = ImageUpscalingFilter.None; - SuperResolutionParamSets.Instance.Set("MipmapBias", v1settings.MipMapBias); + SuperResolutionParamSets.Instance.Set("MipmapBias", Fsr2.GetMipmapBiasOffset(source.referenceSize.x, cameraData.camera.pixelWidth)); cmd.SetGlobalVector(ViewportInfoId, new Vector4(1.0f / pixW, 1.0f / pixH, pixW, pixH)); cmd.SetGlobalVector(GSR1ParamsId, new Vector4(v1settings.Mode, v1settings.Sharp, 0, 0)); @@ -238,18 +236,25 @@ namespace X.Rendering.Feature private RTHandle motionDepthClipAlphaBuffer; private RTHandle prevSceneColorTexture1; private RTHandle prevSceneColorTexture2; + + private RTHandle prevLumaTexture1; + private RTHandle prevLumaTexture2; + private RTHandle YCoCgColor; - public float4x4 clipToPrevClip; - public float4 renderSizeParam; - public float4 outputSizeParam; - public float2 jitterOffset; - public float2 scaleRatio; - public float cameraFovAngleHor; - public float minLerpContribution; - public int sameCameraFrmNum; + private RTHandle motionDepthAlphaBuffer; + private float4x4 clipToPrevClip; + private float4 renderSizeParam; + private float4 outputSizeParam; + private float2 jitterOffset; + private float2 scaleRatio; + private float cameraFovAngleHor; + private float minLerpContribution; + private int sameCameraFrmNum; + private float viewportXScale; + public GSRV2(GSR.V2Setting v2settings) { for (int i = 0; i < 32; ++i) @@ -296,61 +301,127 @@ namespace X.Rendering.Feature cmdBuffer.CopyTexture(destination, prevSceneColorTexture1); } - private void DispatchConvert(CommandBuffer cmdBuffer, RTHandle source, RTHandle motionVector, ref RenderingData renderingData) + private void DispatchConvert2ps(CommandBuffer cmdBuffer, RTHandle source, RTHandle motionVector, ref RenderingData renderingData) { - var gsrv2 = v2settings.GSRV2ComputeShader; - cmdBuffer.SetComputeTextureParam(gsrv2, 0, "InputDepth", renderingData.cameraData.renderer.cameraDepthTargetHandle); - cmdBuffer.SetComputeTextureParam(gsrv2, 0, "InputVelocity", motionVector); - cmdBuffer.SetComputeTextureParam(gsrv2, 0, "InputColor", source); - cmdBuffer.SetComputeMatrixParam(gsrv2, "_clipToPrevClip", clipToPrevClip); - cmdBuffer.SetComputeVectorParam(gsrv2, "_renderSizeParam", renderSizeParam); - cmdBuffer.SetComputeVectorParam(gsrv2, "_outputSizeParam", outputSizeParam); - cmdBuffer.SetComputeFloatParams(gsrv2, "_cameraFovAngleHor", cameraFovAngleHor); - cmdBuffer.SetComputeFloatParams(gsrv2, "Exposure_co_rcp", v2settings.Exposure_co_rcp); + var compute = v2settings.GSR2psComputeShader; + cmdBuffer.SetComputeTextureParam(compute, 0, "InputDepth", renderingData.cameraData.renderer.cameraDepthTargetHandle); + cmdBuffer.SetComputeTextureParam(compute, 0, "InputVelocity", motionVector); + cmdBuffer.SetComputeTextureParam(compute, 0, "InputColor", source); + cmdBuffer.SetComputeMatrixParam(compute, "_clipToPrevClip", clipToPrevClip); + cmdBuffer.SetComputeVectorParam(compute, "_renderSizeParam", renderSizeParam); + cmdBuffer.SetComputeVectorParam(compute, "_outputSizeParam", outputSizeParam); + cmdBuffer.SetComputeFloatParam(compute, "_cameraFovAngleHor", cameraFovAngleHor); + cmdBuffer.SetComputeFloatParam(compute, "Exposure_co_rcp", v2settings.Exposure_co_rcp); - cmdBuffer.SetComputeTextureParam(gsrv2, 0, "MotionDepthClipAlphaBuffer", motionDepthClipAlphaBuffer); - cmdBuffer.SetComputeTextureParam(gsrv2, 0, "YCoCgColor", YCoCgColor); - cmdBuffer.DispatchCompute(gsrv2, 0, Mathf.CeilToInt(renderSizeParam.x / 8), Mathf.CeilToInt(renderSizeParam.y / 8), 1); + cmdBuffer.SetComputeTextureParam(compute, 0, "MotionDepthClipAlphaBuffer", motionDepthClipAlphaBuffer); + cmdBuffer.SetComputeTextureParam(compute, 0, "YCoCgColor", YCoCgColor); + cmdBuffer.DispatchCompute(compute, 0, Mathf.CeilToInt(renderSizeParam.x / 8), Mathf.CeilToInt(renderSizeParam.y / 8), 1); } - private void DispatchUpscale(CommandBuffer cmdBuffer, RTHandle historyIn, RTHandle historyOut, RTHandle destination) + private void DispatchUpscale2ps(CommandBuffer cmdBuffer, RTHandle historyIn, RTHandle historyOut, RTHandle destination) { - var gsrv2 = v2settings.GSRV2ComputeShader; + var compute = v2settings.GSR2psComputeShader; SuperResolutionParamSets.Instance.Set("NeedJitter", true); var jitter = TemporalAA.CurrentJitter; - cmdBuffer.SetComputeTextureParam(gsrv2, 1, "_inputPrevHistoryOutput", historyIn); - cmdBuffer.SetComputeTextureParam(gsrv2, 1, "_inputYCoCgColor", YCoCgColor); - cmdBuffer.SetComputeTextureParam(gsrv2, 1, "_inputMotionDepthClipAlphaBuffer", motionDepthClipAlphaBuffer); + cmdBuffer.SetComputeTextureParam(compute, 1, "_inputPrevHistoryOutput", historyIn); + cmdBuffer.SetComputeTextureParam(compute, 1, "_inputYCoCgColor", YCoCgColor); + cmdBuffer.SetComputeTextureParam(compute, 1, "_inputMotionDepthClipAlphaBuffer", motionDepthClipAlphaBuffer); - cmdBuffer.SetComputeMatrixParam(gsrv2, "_clipToPrevClip", clipToPrevClip); - cmdBuffer.SetComputeVectorParam(gsrv2, "_renderSizeParam", renderSizeParam); - cmdBuffer.SetComputeVectorParam(gsrv2, "_outputSizeParam", outputSizeParam); - cmdBuffer.SetComputeFloatParams(gsrv2, "_cameraFovAngleHor", cameraFovAngleHor); - cmdBuffer.SetComputeFloatParams(gsrv2, "minLerpContribution", minLerpContribution); - cmdBuffer.SetComputeFloatParams(gsrv2, "Exposure_co_rcp", v2settings.Exposure_co_rcp); + cmdBuffer.SetComputeMatrixParam(compute, "_clipToPrevClip", clipToPrevClip); + cmdBuffer.SetComputeVectorParam(compute, "_renderSizeParam", renderSizeParam); + cmdBuffer.SetComputeVectorParam(compute, "_outputSizeParam", outputSizeParam); + cmdBuffer.SetComputeFloatParam(compute, "_cameraFovAngleHor", cameraFovAngleHor); + cmdBuffer.SetComputeFloatParam(compute, "minLerpContribution", minLerpContribution); + cmdBuffer.SetComputeFloatParam(compute, "Exposure_co_rcp", v2settings.Exposure_co_rcp); cmdBuffer.SetGlobalVector("_JitterOffset", jitter); if (v2settings.FiveSample) { - gsrv2.EnableKeyword("SAMPLE_NUMBER"); + compute.EnableKeyword("SAMPLE_NUMBER"); } else { - gsrv2.DisableKeyword("SAMPLE_NUMBER"); + compute.DisableKeyword("SAMPLE_NUMBER"); } - cmdBuffer.SetComputeTextureParam(gsrv2, 1, "HistoryOutput", historyOut); - cmdBuffer.SetComputeTextureParam(gsrv2, 1, "SceneColorOutput", destination); + cmdBuffer.SetComputeTextureParam(compute, 1, "HistoryOutput", historyOut); + cmdBuffer.SetComputeTextureParam(compute, 1, "SceneColorOutput", destination); - cmdBuffer.DispatchCompute(gsrv2, 1, Mathf.CeilToInt(outputSizeParam.x / 8), Mathf.CeilToInt(outputSizeParam.y / 8), 1); + cmdBuffer.DispatchCompute(compute, 1, Mathf.CeilToInt(outputSizeParam.x / 8), Mathf.CeilToInt(outputSizeParam.y / 8), 1); } + private void DispatchConvert3ps(CommandBuffer cmdBuffer, RTHandle source, RTHandle motionVector, ref RenderingData renderingData) + { + var compute = v2settings.GSR3psComputeShader; + + cmdBuffer.SetComputeTextureParam(compute, 0, "InputDepth", renderingData.cameraData.renderer.cameraDepthTargetHandle); + cmdBuffer.SetComputeTextureParam(compute, 0, "InputVelocity", motionVector); + cmdBuffer.SetComputeTextureParam(compute, 0, "InputColor", source); + cmdBuffer.SetComputeTextureParam(compute, 0, "InputOpaqueColor", Shader.GetGlobalTexture("_CameraOpaqueTexture")); + cmdBuffer.SetComputeMatrixParam(compute, "ReClipToPrevClip", clipToPrevClip); + cmdBuffer.SetComputeVectorParam(compute, "RenderSizeParam", renderSizeParam); + cmdBuffer.SetComputeVectorParam(compute, "OutputSizeParam", outputSizeParam); + cmdBuffer.SetComputeFloatParam(compute, "Exposure_co_rcp", v2settings.Exposure_co_rcp); + + cmdBuffer.SetComputeTextureParam(compute, 0, "ConvertOutMotionDepthAlphaBuffer", motionDepthAlphaBuffer); + cmdBuffer.SetComputeTextureParam(compute, 0, "ConvertOutYCoCgColor", YCoCgColor); + cmdBuffer.DispatchCompute(compute, 0, Mathf.CeilToInt(renderSizeParam.x / 8), Mathf.CeilToInt(renderSizeParam.y / 8), 1); + } + + private void DispatchActivate3ps(CommandBuffer cmdBuffer, RTHandle historyIn, RTHandle historyOut) + { + var compute = v2settings.GSR3psComputeShader; + cmdBuffer.SetComputeTextureParam(compute, 1, "ActivateInYCoCgColor", YCoCgColor); + cmdBuffer.SetComputeTextureParam(compute, 1, "ActivateInMotionDepthAlphaBuffer", motionDepthAlphaBuffer); + + cmdBuffer.SetComputeFloatParam(compute, "ValidReset", 0); + cmdBuffer.SetComputeFloatParam(compute, "AngleVertical", cameraFovAngleHor); + + + cmdBuffer.SetComputeTextureParam(compute, 1, "MotionDepthClipAlphaBuffer", motionDepthClipAlphaBuffer); + cmdBuffer.SetComputeTextureParam(compute, 1, "PrevLumaHistory", historyIn); + cmdBuffer.SetComputeTextureParam(compute, 1, "LumaHistory", historyOut); + + cmdBuffer.DispatchCompute(compute, 1, Mathf.CeilToInt(renderSizeParam.x / 8), Mathf.CeilToInt(renderSizeParam.y / 8), 1); + } + + + private void DispatchUpscale3ps(CommandBuffer cmdBuffer, RTHandle historyIn, RTHandle historyOut, RTHandle destination) + { + var compute = v2settings.GSR3psComputeShader; + SuperResolutionParamSets.Instance.Set("NeedJitter", true); + var jitter = TemporalAA.CurrentJitter; + + cmdBuffer.SetComputeTextureParam(compute, 2, "UpscaleInYCoCgColor", YCoCgColor); + cmdBuffer.SetComputeTextureParam(compute, 2, "UpscaleInMotionDepthClipAlphaBuffer", motionDepthClipAlphaBuffer); + cmdBuffer.SetComputeTextureParam(compute, 2, "UpscaleOutPrevHistoryOutput", historyIn); + + cmdBuffer.SetComputeTextureParam(compute, 2, "HistoryOutput", historyOut); + + cmdBuffer.SetComputeTextureParam(compute, 2, "SceneColorOutput", destination); + + cmdBuffer.SetGlobalVector("InputJitter", jitter); + cmdBuffer.SetComputeFloatParam(compute, "Scalefactor", scaleRatio.y); + cmdBuffer.SetComputeFloatParam(compute, "Biasmax_viewportXScale", viewportXScale); + + + if (v2settings.FiveSample) + { + compute.EnableKeyword("SAMPLE_NUMBER"); + } + else + { + compute.DisableKeyword("SAMPLE_NUMBER"); + } + + cmdBuffer.DispatchCompute(compute, 2, Mathf.CeilToInt(outputSizeParam.x / 8), Mathf.CeilToInt(outputSizeParam.y / 8), 1); + } public void DoSR(CommandBuffer cmd, RTHandle source, RTHandle destination, RTHandle motionVector, ref RenderingData renderingData) { using (new ProfilingScope(cmd, profiler)) { - bool useCompute = v2settings.UseCompute2Pass; + bool useCompute = v2settings.UseCompute2Pass || v2settings.UseCompute3Pass || v2settings.useCompute; var camera = renderingData.cameraData.camera; var clip2View = camera.projectionMatrix.inverse; var vcenter = clip2View.MultiplyPoint(Vector3.zero).normalized; @@ -372,6 +443,42 @@ namespace X.Rendering.Feature outputSizeParam = new(camera.pixelWidth, camera.pixelHeight, 1.0f / camera.pixelWidth, 1.0f / camera.pixelHeight); scaleRatio = new float2((float)(camera.pixelWidth) / (float)(source.referenceSize.x), math.min(20.0f, math.pow(((float)camera.pixelWidth * camera.pixelHeight) / ((float)source.referenceSize.x * source.referenceSize.y), 3.0f))); + viewportXScale = math.min((camera.pixelWidth / (float)source.referenceSize.x), 1.99f); + if (v2settings.UseCompute3Pass) + { + RenderingUtils.ReAllocateIfNeeded(ref motionDepthAlphaBuffer, name: "motionDepthAlphaBuffer", descriptor: new RenderTextureDescriptor() + { + width = source.referenceSize.x, + height = source.referenceSize.y, + colorFormat = RenderTextureFormat.ARGBHalf, + depthBufferBits = 0, + enableRandomWrite = useCompute ? true : false, + dimension = TextureDimension.Tex2D, + msaaSamples = 1 + }); + + RenderingUtils.ReAllocateIfNeeded(ref prevLumaTexture1, name: "prevLumaTexture1", descriptor: new RenderTextureDescriptor() + { + width = source.referenceSize.x, + height = source.referenceSize.y, + graphicsFormat = GraphicsFormat.R32_UInt, + depthBufferBits = 0, + enableRandomWrite = true, + dimension = TextureDimension.Tex2D, + msaaSamples = 1, + }); + RenderingUtils.ReAllocateIfNeeded(ref prevLumaTexture2, name: "prevLumaTexture2", descriptor: new RenderTextureDescriptor() + { + width = source.referenceSize.x, + height = source.referenceSize.y, + graphicsFormat = GraphicsFormat.R32_UInt, + depthBufferBits = 0, + enableRandomWrite = true, + dimension = TextureDimension.Tex2D, + msaaSamples = 1, + }); + } + RenderingUtils.ReAllocateIfNeeded(ref motionDepthClipAlphaBuffer, name: "motionDepthClipAlphaBuffer", descriptor: new RenderTextureDescriptor() { width = source.referenceSize.x, @@ -402,11 +509,10 @@ namespace X.Rendering.Feature dimension = TextureDimension.Tex2D, msaaSamples = 1, }); - SuperResolutionParamSets.Instance.Set("MipmapBias", v2settings.MipMapBias); + SuperResolutionParamSets.Instance.Set("MipmapBias", Fsr2.GetMipmapBiasOffset(source.referenceSize.x, camera.pixelWidth)); - if (v2settings.UseCompute2Pass) + if (useCompute) { - RenderingUtils.ReAllocateIfNeeded(ref YCoCgColor, name: "YCoCgColor", descriptor: new RenderTextureDescriptor() { width = source.referenceSize.x, @@ -417,15 +523,38 @@ namespace X.Rendering.Feature dimension = TextureDimension.Tex2D, msaaSamples = 1 }); - - DispatchConvert(cmd, source, motionVector, ref renderingData); - if (jitterIndex % 2 == 0) + if (v2settings.UseCompute3Pass) { - DispatchUpscale(cmd, prevSceneColorTexture1, prevSceneColorTexture2, destination); + DispatchConvert3ps(cmd, source, motionVector, ref renderingData); } else { - DispatchUpscale(cmd, prevSceneColorTexture2, prevSceneColorTexture1, destination); + DispatchConvert2ps(cmd, source, motionVector, ref renderingData); + } + if (jitterIndex % 2 == 0) + { + if (v2settings.UseCompute3Pass) + { + + DispatchActivate3ps(cmd, prevLumaTexture1, prevLumaTexture2); + DispatchUpscale3ps(cmd, prevSceneColorTexture1, prevSceneColorTexture2, destination); + } + else + { + DispatchUpscale2ps(cmd, prevSceneColorTexture1, prevSceneColorTexture2, destination); + } + } + else + { + if (v2settings.UseCompute3Pass) + { + DispatchActivate3ps(cmd, prevLumaTexture2, prevLumaTexture1); + DispatchUpscale3ps(cmd, prevSceneColorTexture2, prevSceneColorTexture1, destination); + } + else + { + DispatchUpscale2ps(cmd, prevSceneColorTexture2, prevSceneColorTexture1, destination); + } } } else diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS2/XeSS.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS2/XeSS.cs index 04bdbe3..536e63c 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS2/XeSS.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS2/XeSS.cs @@ -891,6 +891,11 @@ namespace Intel usingFixedJitterPhaseCount = isUsingFixedJitterPhaseCount; } + public static float GetMipmapBiasOffset(int renderWidth, int displayWidth) + { + return Mathf.Log((float)renderWidth / displayWidth, 2.0f); + } + public static float GetMipmapBiasOffset(uint renderWidth, uint displayWidth) { return Mathf.Log((float)renderWidth / displayWidth, 2.0f); diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2.compute b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_2ps.compute similarity index 99% rename from Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2.compute rename to Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_2ps.compute index a093a77..d0c770d 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2.compute +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_2ps.compute @@ -123,7 +123,7 @@ float ValidReset; float minLerpContribution;// 0.0 or 0.3, when camera move 0.0, camera freeze 0.3 RWTexture2D HistoryOutput; -RWTexture2D SceneColorOutput; +RWTexture2D SceneColorOutput; float FastLanczos(float base) { @@ -345,9 +345,10 @@ void Update(uint2 DisThreadID) rectboxcenter += wsample; rectboxvar += (samplecolor * wsample); rectboxweight += boxweight; + } #endif - + rectboxweight = 1.0f / rectboxweight; rectboxcenter *= rectboxweight; rectboxvar *= rectboxweight; diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2.compute.meta b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_2ps.compute.meta similarity index 100% rename from Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2.compute.meta rename to Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_2ps.compute.meta diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_3ps.compute b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_3ps.compute new file mode 100644 index 0000000..8d97531 --- /dev/null +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_3ps.compute @@ -0,0 +1,563 @@ +#pragma enable_d3d11_debug_symbols + +#pragma kernel ConvertKernel +#pragma kernel ActivateKernal +#pragma kernel UpsacleKernal + +#pragma multi_compile_local __ SAMPLE_NUMBER + +#if COMPILER_GLSL_ES3_1 +Texture2D InputVelocity; +#else +Texture2D InputVelocity; +#endif +Texture2D InputDepth; +Texture2D InputColor; +Texture2D InputOpaqueColor; +float Exposure_co_rcp; +float4x4 ReClipToPrevClip; + +SamplerState PointClamp; +SamplerState PointClamp_Velocity; + +RWTexture2D ConvertOutYCoCgColor; +RWTexture2D ConvertOutMotionDepthAlphaBuffer; +float4 RenderSizeParam; +float4 OutputSizeParam; + +void Convert(uint2 DisThreadID) +{ + int2 PixelOffset; + PixelOffset.x = 0; //store int2(1, 1) - int2(1, 1) + float2 gatherCoord = float2(DisThreadID) * RenderSizeParam.zw; + float2 ViewportUV = gatherCoord + float2(0.5f, 0.5f) * RenderSizeParam.zw; + gatherCoord = float2(DisThreadID) * RenderSizeParam.zw; + + int2 InputPosBtmRight = int2(1, 1) + DisThreadID; + float NearestZ = InputDepth[InputPosBtmRight].x; //bottom right z + float4 topleft = InputDepth.GatherRed(PointClamp, gatherCoord); + NearestZ = max(topleft.x, NearestZ); + NearestZ = max(topleft.y, NearestZ); + NearestZ = max(topleft.z, NearestZ); + NearestZ = max(topleft.w, NearestZ); + + float2 topRight = InputDepth.GatherRed(PointClamp, gatherCoord + float2(RenderSizeParam.zw.x, 0.0)).yz; + NearestZ = max(topRight.x, NearestZ); + NearestZ = max(topRight.y, NearestZ); + + float2 bottomLeft = InputDepth.GatherRed(PointClamp, gatherCoord + float2(0.0, RenderSizeParam.zw.y)).xy; + NearestZ = max(bottomLeft.x, NearestZ); + NearestZ = max(bottomLeft.y, NearestZ); + + +#if COMPILER_GLSL_ES3_1 + uint4 velocity; + velocity.x = InputVelocity.GatherRed(PointClamp_Velocity, gatherCoord).y; + velocity.y = InputVelocity.GatherGreen(PointClamp_Velocity, gatherCoord).y; +#else + float4 velocity = InputVelocity[DisThreadID]; +#endif + + float2 motion; + if (float(velocity.x) > 0.0) + { + motion = velocity.xy; + } + else + { + float2 ScreenPos = float2(2 * ViewportUV.x - 1, 1 - 2 * ViewportUV.y); + float3 Position = float3(ScreenPos, NearestZ); + float4 CurClip = float4(Position, 1); + float4 PreClip = mul(CurClip, ReClipToPrevClip); + float2 PreScreen = PreClip.xy / PreClip.w; + motion = Position.xy - PreScreen; + } + + float3 Colorrgb = InputColor[DisThreadID].xyz; + ///simple tonemap + float ColorMax = (max(max(Colorrgb.x, Colorrgb.y), Colorrgb.z) + Exposure_co_rcp).x; + Colorrgb /= ColorMax.xxx; + + float depth_bright = floor(ColorMax * 0.001f) + NearestZ; + + float3 Colorycocg; + Colorycocg.x = 0.25f * (Colorrgb.x + 2.0f * Colorrgb.y + Colorrgb.z), + Colorycocg.y = saturate(0.5f * Colorrgb.x + 0.5 - 0.5f * Colorrgb.z), + Colorycocg.z = saturate(Colorycocg.x + Colorycocg.y - Colorrgb.x); + + //now color YCoCG all in the range of [0,1] + uint x11 = Colorycocg.x * 2047.5; + uint y11 = Colorycocg.y * 2047.5; + uint z10 = Colorycocg.z * 1023.5; + + float3 Colorprergb = InputOpaqueColor[DisThreadID].xyz; + ///simple tonemap + Colorprergb /= (max(max(Colorprergb.x, Colorprergb.y), Colorprergb.z) + Exposure_co_rcp).xxx; + float3 delta = abs(Colorrgb - Colorprergb); + float alpha_mask = max(delta.x, max(delta.y, delta.z)); + alpha_mask = (0.35f * 1000.0f) * alpha_mask; + + ConvertOutYCoCgColor[DisThreadID] = (x11 << 21) | (y11 << 10) | z10; + ConvertOutMotionDepthAlphaBuffer[DisThreadID] = half4(motion, depth_bright, alpha_mask); +} + + +#define TILE_SIZE_X 8 +#define TILE_SIZE_Y 8 + +[numthreads(TILE_SIZE_X, TILE_SIZE_Y, 1)] +void ConvertKernel(uint2 uGroupId : SV_GroupID, + uint2 uGroupThreadId : SV_GroupThreadID, + uint2 uDispatchThreadId : SV_DispatchThreadID) +{ + Convert(uDispatchThreadId); +} + + +Texture2D ActivateInYCoCgColor; +Texture2D ActivateInMotionDepthAlphaBuffer; + +float ValidReset; +float AngleVertical; +SamplerState PointClamp1; +SamplerState PointClamp2; +SamplerState PointClamp3; + +Texture2D PrevLumaHistory; +RWTexture2D LumaHistory; + +RWTexture2D MotionDepthClipAlphaBuffer; + +#define EPSILON 1.19e-07f /*1.192092896e-07f*/ + +float DecodeColorY(uint sample32) +{ + uint x11 = sample32 >> 21; + return ((float)x11 * (1.0 / 2047.5)); +} + +void Activate(uint2 DisThreadID) +{ + const int2 sampleOffset[4] = { + int2(-1, -1), + int2(-1, +0), + int2(+0, -1), + int2(+0, +0), + }; + + float2 ViewportUV = (float2(DisThreadID) + 0.5f) * RenderSizeParam.zw; + float2 gatherCoord = ViewportUV + 0.5f * RenderSizeParam.zw; + uint luma_reference32 = ActivateInYCoCgColor.GatherRed(PointClamp1, gatherCoord).w; + float luma_reference = DecodeColorY(luma_reference32); + + float4 mda = ActivateInMotionDepthAlphaBuffer[DisThreadID].xyzw; //motion depth alpha + float depth = frac(mda.z); + float depth_base = mda.z - depth; + float alphamask = mda.w; + float2 motion = mda.xy; + + float2 PrevUV; + PrevUV.x = -0.5f * motion.x + ViewportUV.x; + PrevUV.y = 0.5f * motion.y + ViewportUV.y; + + float depthclip = 0.0; + + if (depth > 1.0e-05f) + { + + float2 Prevf_sample = PrevUV * RenderSizeParam.xy - 0.5f; + float2 Prevfrac = Prevf_sample - floor(Prevf_sample); + + float OneMinusPrevfacx = (1 - Prevfrac.x); + float Bilinweights[4] = { + OneMinusPrevfacx - OneMinusPrevfacx * Prevfrac.y, + (Prevfrac.x - Prevfrac.x * Prevfrac.y), + OneMinusPrevfacx * (Prevfrac.y), + (Prevfrac.x) * (Prevfrac.y) + }; + float Wdepth = 0.f; + float Wsum = 0.f; + float Ksep = 1.37e-05f; + float Kfov = AngleVertical; /** (RenderSizeParam.xy.x / RenderSizeParam.xy.y)*/ + float diagonal_length = length(float2(RenderSizeParam.xy)); + float Ksep_Kfov_diagonal = Ksep * Kfov * diagonal_length; + for (int index = 0; index < 4; index += 2) + { + float4 gPrevdepth = ActivateInMotionDepthAlphaBuffer.GatherBlue(PointClamp2, PrevUV, sampleOffset[index]); + float tdepth1 = max(frac(gPrevdepth.x), frac(gPrevdepth.y)); + float tdepth2 = max(frac(gPrevdepth.z), frac(gPrevdepth.w)); + float fPrevdepth = max(tdepth1, tdepth2); + + float Depthsep = Ksep_Kfov_diagonal * max(fPrevdepth, depth); + float weight = Bilinweights[index]; + Wdepth += saturate(Depthsep / (abs(fPrevdepth - depth) + EPSILON)) * weight; + + float2 gPrevdepth2 = ActivateInMotionDepthAlphaBuffer.GatherBlue(PointClamp2, PrevUV, sampleOffset[index + 1]).zw; + fPrevdepth = max(max(frac(gPrevdepth2.x), frac(gPrevdepth2.y)), tdepth2); + Depthsep = Ksep_Kfov_diagonal * max(fPrevdepth, depth); + weight = Bilinweights[index + 1]; + Wdepth += saturate(Depthsep / (abs(fPrevdepth - depth) + EPSILON)) * weight; + } + depthclip = saturate(1.0f - Wdepth); + } + + float2 current_luma_diff; + uint prev_lumadiff_pack = PrevLumaHistory.GatherRed(PointClamp3, PrevUV).w; + float2 prev_luma_diff; + + prev_luma_diff.x = f16tof32(prev_lumadiff_pack >> 16); + prev_luma_diff.y = f16tof32(prev_lumadiff_pack & 0xffff); + + bool enable = false; + if (depthclip + ValidReset < 0.1f) + { + enable = all(PrevUV >= 0.0f) && all(PrevUV <= 1.0f); + } + + float luma_diff = luma_reference - prev_luma_diff.x; + if (!enable) + { + current_luma_diff.x = 0.0f; + current_luma_diff.y = 0.0f; + } + else + { + current_luma_diff.x = luma_reference; + current_luma_diff.y = prev_luma_diff.y != 0.0f ? (sign(luma_diff) == sign(prev_luma_diff.y) ? sign(luma_diff) * min(abs(prev_luma_diff.y), abs(luma_diff)) : prev_luma_diff.y) : luma_diff; + } + + alphamask = floor(alphamask) + 0.5f * (float)((current_luma_diff.x != 0.0f) && (abs(current_luma_diff.y) != abs(luma_diff))); + + uint pack = (f32tof16(current_luma_diff.x) << 16) | f32tof16(current_luma_diff.y); + depthclip = depthclip + depth_base; + LumaHistory[DisThreadID] = pack; + MotionDepthClipAlphaBuffer[DisThreadID] = float4(motion, depthclip, alphamask); +} + +[numthreads(TILE_SIZE_X, TILE_SIZE_Y, 1)] +void ActivateKernal(uint2 uGroupId : SV_GroupID, + uint2 uGroupThreadId : SV_GroupThreadID, + uint2 uDispatchThreadId : SV_DispatchThreadID) +{ + Activate(uDispatchThreadId); +} + + + +#define five_sample_use SAMPLE_NUMBER + +Texture2D UpscaleInYCoCgColor; +Texture2D UpscaleInMotionDepthClipAlphaBuffer; +Texture2D UpscaleOutPrevHistoryOutput; + +SamplerState LinearClamp1; +SamplerState LinearClamp2; +float Scalefactor; +float Biasmax_viewportXScale; +float2 InputJitter; + +RWTexture2D HistoryOutput; +RWTexture2D SceneColorOutput; + +float FastLanczos(float base) +{ + float y = base - 1; + float y2 = y * y; + float y_temp = 0.75 * y + y2; + return y_temp * y2; +} + +float3 DecodeColor(uint sample32) +{ + uint x11 = sample32 >> 21; + uint y11 = sample32 & (2047 << 10); + uint z10 = sample32 & 1023; + float3 samplecolor; + samplecolor.x = ((float)x11 * (1.0f / 2047.5f)); + samplecolor.y = ((float)y11 * (4.76953602e-7f)) - 0.5f; + samplecolor.z = ((float)z10 * (1.0f / 1023.5f)) - 0.5f; + return samplecolor; +} + +void Update(uint2 DisThreadID) +{ + float2 Hruv = (DisThreadID + 0.5f) * OutputSizeParam.zw; + float2 Jitteruv; + Jitteruv.x = clamp(Hruv.x + InputJitter.x * RenderSizeParam.zw.x, 0.0f, 1.0f); + Jitteruv.y = clamp(Hruv.y + InputJitter.y * RenderSizeParam.zw.y, 0.0f, 1.0f); + int2 InputPos = Jitteruv * RenderSizeParam.xy; + + float4 mda = UpscaleInMotionDepthClipAlphaBuffer.SampleLevel(LinearClamp1, Jitteruv, 0).xyzw; + float2 Motion = mda.xy; + mda.w = UpscaleInMotionDepthClipAlphaBuffer[InputPos].w; + ///ScreenPosToViewportScale&Bias + float2 PrevUV; + PrevUV.x = -0.5f * Motion.x + Hruv.x; + PrevUV.y = 0.5f * Motion.y + Hruv.y; + + PrevUV.x = clamp(PrevUV.x, 0.0f, 1.0f); + PrevUV.y = clamp(PrevUV.y, 0.0f, 1.0f); + + float depthfactor = frac(mda.z); + float bright = (mda.z - depthfactor) * 1000.0f; + float history_value = frac(mda.w); + float alphamask = (mda.w - history_value) * 0.001f; + history_value *= 2; + + float4 History = UpscaleOutPrevHistoryOutput.SampleLevel(LinearClamp2, PrevUV, 0); + float3 HistoryColor = History.xyz; + float Historyw = History.w; + float Wfactor = max(saturate(abs(Historyw)), alphamask); + + /////upsample and compute box + float4 Upsampledcw = float4(0.0f, 0.0f, 0.0f, 0.0f); + float kernelfactor = saturate(Wfactor + ValidReset); + float biasmax = Biasmax_viewportXScale - Biasmax_viewportXScale * kernelfactor; + float biasmin = max(1.0f, 0.3f + 0.3f * biasmax); + float biasfactor = max(0.25f * depthfactor, kernelfactor); + float kernelbias = lerp(biasmax, biasmin, biasfactor); + float motion_viewport_len = length(Motion * OutputSizeParam.xy); + float curvebias = lerp(-2.0f, -3.0f, saturate(motion_viewport_len * 0.02f)); + + float3 rectboxcenter = float3(0.0f, 0.0f, 0.0f); + float3 rectboxvar = float3(0.0f, 0.0f, 0.0f); + float rectboxweight = 0.0f; + + float2 srcpos = InputPos + float2(0.5f, 0.5f) - InputJitter; + float2 srcOutputPos = Hruv * RenderSizeParam.xy; + + kernelbias *= 0.5f; + float kernelbias2 = kernelbias * kernelbias; + float2 srcpos_srcOutputPos = srcpos - srcOutputPos; + + int2 InputPosBtmRight = int2(1, 1) + InputPos; + float2 gatherCoord = float2(InputPos) * RenderSizeParam.zw; + uint4 topleft = UpscaleInYCoCgColor.GatherRed(PointClamp, gatherCoord); + uint2 topRight; + uint2 bottomLeft; + +#if five_sample_use + uint2 btmRight = UpscaleInYCoCgColor.GatherRed(PointClamp, gatherCoord + float2(RenderSizeParam.zw.x, RenderSizeParam.zw.y)).xz; + bottomLeft.y = btmRight.x; + topRight.x = btmRight.y; +#else + topRight = UpscaleInYCoCgColor.GatherRed(PointClamp, gatherCoord + float2(RenderSizeParam.zw.x, 0.0)).yz; + bottomLeft = UpscaleInYCoCgColor.GatherRed(PointClamp, gatherCoord + float2(0.0, RenderSizeParam.zw.y)).xy; +#endif + + float3 rectboxmin; + float3 rectboxmax; + + { + float3 samplecolor = DecodeColor(bottomLeft.y); + float2 baseoffset = srcpos_srcOutputPos + float2(0.0, 1.0); + float baseoffset_dot = dot(baseoffset, baseoffset); + float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f); + float weight = FastLanczos(base); + Upsampledcw = float4(samplecolor * weight, weight); + float boxweight = exp(baseoffset_dot * curvebias); + rectboxmin = samplecolor; + rectboxmax = samplecolor; + float3 wsample = samplecolor * boxweight; + rectboxcenter = wsample; + rectboxvar = (samplecolor * wsample); + rectboxweight = boxweight; + } + { + float3 samplecolor = DecodeColor(topRight.x); + float2 baseoffset = srcpos_srcOutputPos + float2(1.0, 0.0); + float baseoffset_dot = dot(baseoffset, baseoffset); + float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f); + float weight = FastLanczos(base); + Upsampledcw += float4(samplecolor * weight, weight); + float boxweight = exp(baseoffset_dot * curvebias); + rectboxmin = min(rectboxmin, samplecolor); + rectboxmax = max(rectboxmax, samplecolor); + float3 wsample = samplecolor * boxweight; + rectboxcenter += wsample; + rectboxvar += (samplecolor * wsample); + rectboxweight += boxweight; + } + { + float3 samplecolor = DecodeColor(topleft.x); + float2 baseoffset = srcpos_srcOutputPos + float2(-1.0, 0.0); + float baseoffset_dot = dot(baseoffset, baseoffset); + float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f); + float weight = FastLanczos(base); + Upsampledcw += float4(samplecolor * weight, weight); + float boxweight = exp(baseoffset_dot * curvebias); + rectboxmin = min(rectboxmin, samplecolor); + rectboxmax = max(rectboxmax, samplecolor); + float3 wsample = samplecolor * boxweight; + rectboxcenter += wsample; + rectboxvar += (samplecolor * wsample); + rectboxweight += boxweight; + } + { + float3 samplecolor = DecodeColor(topleft.y); + float2 baseoffset = srcpos_srcOutputPos; + float baseoffset_dot = dot(baseoffset, baseoffset); + float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f); + float weight = FastLanczos(base); + Upsampledcw += float4(samplecolor * weight, weight); + float boxweight = exp(baseoffset_dot * curvebias); + rectboxmin = min(rectboxmin, samplecolor); + rectboxmax = max(rectboxmax, samplecolor); + float3 wsample = samplecolor * boxweight; + rectboxcenter += wsample; + rectboxvar += (samplecolor * wsample); + rectboxweight += boxweight; + } + { + float3 samplecolor = DecodeColor(topleft.z); + float2 baseoffset = srcpos_srcOutputPos + float2(0.0, -1.0); + float baseoffset_dot = dot(baseoffset, baseoffset); + float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f); + float weight = FastLanczos(base); + Upsampledcw += float4(samplecolor * weight, weight); + float boxweight = exp(baseoffset_dot * curvebias); + rectboxmin = min(rectboxmin, samplecolor); + rectboxmax = max(rectboxmax, samplecolor); + float3 wsample = samplecolor * boxweight; + rectboxcenter += wsample; + rectboxvar += (samplecolor * wsample); + rectboxweight += boxweight; + } + +#if !five_sample_use + { + uint btmRight = UpscaleInYCoCgColor[InputPosBtmRight].x; + float3 samplecolor = DecodeColor(btmRight); + float2 baseoffset = srcpos_srcOutputPos + float2(1.0, 1.0); + float baseoffset_dot = dot(baseoffset, baseoffset); + float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f); + float weight = FastLanczos(base); + Upsampledcw += float4(samplecolor * weight, weight); + float boxweight = exp(baseoffset_dot * curvebias); + rectboxmin = min(rectboxmin, samplecolor); + rectboxmax = max(rectboxmax, samplecolor); + float3 wsample = samplecolor * boxweight; + rectboxcenter += wsample; + rectboxvar += (samplecolor * wsample); + rectboxweight += boxweight; + } + { + float3 samplecolor = DecodeColor(bottomLeft.x); + float2 baseoffset = srcpos_srcOutputPos + float2(-1.0, 1.0); + float baseoffset_dot = dot(baseoffset, baseoffset); + float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f); + float weight = FastLanczos(base); + Upsampledcw += float4(samplecolor * weight, weight); + float boxweight = exp(baseoffset_dot * curvebias); + rectboxmin = min(rectboxmin, samplecolor); + rectboxmax = max(rectboxmax, samplecolor); + float3 wsample = samplecolor * boxweight; + rectboxcenter += wsample; + rectboxvar += (samplecolor * wsample); + rectboxweight += boxweight; + } + { + float3 samplecolor = DecodeColor(topRight.y); + float2 baseoffset = srcpos_srcOutputPos + float2(1.0, -1.0); + float baseoffset_dot = dot(baseoffset, baseoffset); + float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f); + float weight = FastLanczos(base); + Upsampledcw += float4(samplecolor * weight, weight); + float boxweight = exp(baseoffset_dot * curvebias); + rectboxmin = min(rectboxmin, samplecolor); + rectboxmax = max(rectboxmax, samplecolor); + float3 wsample = samplecolor * boxweight; + rectboxcenter += wsample; + rectboxvar += (samplecolor * wsample); + rectboxweight += boxweight; + } + { + float3 samplecolor = DecodeColor(topleft.w); + float2 baseoffset = srcpos_srcOutputPos + float2(-1.0, -1.0); + float baseoffset_dot = dot(baseoffset, baseoffset); + float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f); + float weight = FastLanczos(base); + Upsampledcw += float4(samplecolor * weight, weight); + float boxweight = exp(baseoffset_dot * curvebias); + rectboxmin = min(rectboxmin, samplecolor); + rectboxmax = max(rectboxmax, samplecolor); + float3 wsample = samplecolor * boxweight; + rectboxcenter += wsample; + rectboxvar += (samplecolor * wsample); + rectboxweight += boxweight; + } +#endif + + rectboxweight = 1.0 / rectboxweight; + rectboxcenter *= rectboxweight; + rectboxvar *= rectboxweight; + rectboxvar = sqrt(abs(rectboxvar - rectboxcenter * rectboxcenter)); + + float3 bias = float3(0.05f, 0.05f, 0.05f); + Upsampledcw.xyz = clamp(Upsampledcw.xyz / Upsampledcw.w, rectboxmin - bias, rectboxmax + bias); + Upsampledcw.w = Upsampledcw.w * (1.0f / 3.0f); + + float tcontribute = history_value * saturate(rectboxvar.x * 10.0f); + float OneMinusWfactor = 1.0f - Wfactor; + tcontribute = tcontribute * OneMinusWfactor; + + float baseupdate = OneMinusWfactor - OneMinusWfactor * depthfactor; + baseupdate = min(baseupdate, lerp(baseupdate, Upsampledcw.w * 10.0f, saturate(10.0f * motion_viewport_len))); + baseupdate = min(baseupdate, lerp(baseupdate, Upsampledcw.w, saturate(motion_viewport_len * 0.05f))); + float basealpha = baseupdate; + + // const float EPSILON = 1.192e-07f; + float boxscale = max(depthfactor, saturate(motion_viewport_len * 0.05f)); + float boxsize = lerp(Scalefactor, 1.0f, boxscale); + + float3 sboxvar = rectboxvar * boxsize; + float3 boxmin = rectboxcenter - sboxvar; + float3 boxmax = rectboxcenter + sboxvar; + rectboxmax = min(rectboxmax, boxmax); + rectboxmin = max(rectboxmin, boxmin); + + 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, saturate(lerpcontribution)); + float basemin = min(basealpha, 0.1f); + basealpha = lerp(basemin, basealpha, saturate(lerpcontribution)); + + ////blend color + float alphasum = max(EPSILON, basealpha + Upsampledcw.w); + float alpha = saturate(Upsampledcw.w / alphasum + ValidReset); + Upsampledcw.xyz = lerp(HistoryColor, Upsampledcw.xyz, alpha.xxx); + + HistoryOutput[DisThreadID] = float4(Upsampledcw.xyz, Wfactor); + ////ycocg to grb + float x_z = Upsampledcw.x - Upsampledcw.z; + Upsampledcw.xyz = float3( + x_z + Upsampledcw.y, + Upsampledcw.x + Upsampledcw.z, + x_z - Upsampledcw.y); + + float compMax = max(Upsampledcw.x, Upsampledcw.y); + float scale; + if (bright > 1000.0f) + { + compMax = clamp(max(compMax, Upsampledcw.z), 0.0f, 1.0f); + scale = bright > 4000.0f ? bright : min(Exposure_co_rcp / ((1.0f + 1.0f / 65504.0f) - compMax), bright); + } + else + { + compMax = clamp(max(compMax, Upsampledcw.z), 0.0f, 254.0f / 255.0f); + scale = Exposure_co_rcp / ((1.0f + 1.0f / 65504.0f) - compMax); + } + Upsampledcw.xyz = Upsampledcw.xyz * scale.xxx; + + SceneColorOutput[DisThreadID] = Upsampledcw.xyz; +} + +[numthreads(TILE_SIZE_X, TILE_SIZE_Y, 1)] +void UpsacleKernal(uint2 uGroupId : SV_GroupID, + uint2 uGroupThreadId : SV_GroupThreadID, + uint2 uDispatchThreadId : SV_DispatchThreadID) +{ + Update(uDispatchThreadId); +} diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_3ps.compute.meta b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_3ps.compute.meta new file mode 100644 index 0000000..14de225 --- /dev/null +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/GSR2_3ps.compute.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e1d5384c19bf4498b85b157bf0642a27 +timeCreated: 1745218976 \ No newline at end of file diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/MRP_SR_GSR1.mat b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/MRP_SR_GSR1.mat index f3a70d6..b8ff99b 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/MRP_SR_GSR1.mat +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Shader/MRP_SR_GSR1.mat @@ -1,5 +1,5 @@ %YAML 1.1 -%TAG !u! tag:yousandi.cn,2023: +%TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: serializedVersion: 8