diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index 117da7e2..60c75990 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -2295,8 +2295,10 @@ namespace UnityEngine.Rendering.HighDefinition { // The variance between 0 and the actual halton sequence values reveals noticeable // instability in Unity's shadow maps, so we avoid index 0. - jitterX = HaltonSequence.Get(taaFrameIndex + 1, 2) - 0.5f; - jitterY = HaltonSequence.Get(taaFrameIndex + 1, 3) - 0.5f; + const float basePhaseCount = 8.0f; + int jitterPhaseCount = (int)(basePhaseCount * Mathf.Pow(screenSize.x / actualWidth, 2.0f)); + jitterX = HaltonSequence.Get((taaFrameIndex % jitterPhaseCount) + 1, 2) - 0.5f; + jitterY = HaltonSequence.Get((taaFrameIndex % jitterPhaseCount) + 1, 3) - 0.5f; } if (!(IsFSR2Enabled() || IsDLSSEnabled() || IsTAAUEnabled() || camera.cameraType == CameraType.SceneView)) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs index fbcbcb60..011ea2ec 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs @@ -265,7 +265,7 @@ namespace UnityEngine.Rendering.HighDefinition ApplyExposure, TemporalAntialiasing, UpscalerColorMask, - FSR2, + AdvancedUpscaling, DeepLearningSuperSampling, DepthOfField, DepthOfFieldKernel, diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs index 49fa46e0..8ae098fa 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs @@ -1001,7 +1001,7 @@ namespace UnityEngine.Rendering.HighDefinition RenderGraph renderGraph, HDCamera hdCamera, TextureHandle source, TextureHandle depthBuffer, TextureHandle motionVectors, TextureHandle biasColorMask) { - using (var builder = renderGraph.AddRenderPass("Fidelity FX 2 Super Resolution", out var passData, ProfilingSampler.Get(HDProfileId.FSR2))) + using (var builder = renderGraph.AddRenderPass("Advanced Temporal Upscaling", out var passData, ProfilingSampler.Get(HDProfileId.AdvancedUpscaling))) { passData.parameters = new FSR2Pass.Parameters(); passData.parameters.hdCamera = hdCamera; @@ -1009,7 +1009,7 @@ namespace UnityEngine.Rendering.HighDefinition var viewHandles = new UpscalerResources.ViewResourceHandles(); viewHandles.source = builder.ReadTexture(source); - viewHandles.output = builder.WriteTexture(GetPostprocessUpsampledOutputHandle(hdCamera, renderGraph, "FSR2 destination")); + viewHandles.output = builder.WriteTexture(GetPostprocessUpsampledOutputHandle(hdCamera, renderGraph, "Upscaling destination")); viewHandles.depth = builder.ReadTexture(depthBuffer); viewHandles.motionVectors = builder.ReadTexture(motionVectors); diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Runtime/FSR3/Fsr3Upscaler.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Runtime/FSR3/Fsr3Upscaler.cs index 56e2a9ab..928b6747 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Runtime/FSR3/Fsr3Upscaler.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Runtime/FSR3/Fsr3Upscaler.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2024 Nico de Poel +// Copyright (c) 2024 Nico de Poel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -202,6 +202,10 @@ namespace FidelityFX.FSR3 public float CameraFovAngleVertical; public float ViewSpaceToMetersFactor; public float VelocityFactor = 1.0f; + public float ReactivenessScale = 1.0f; + public float ShadingChangeScale = 1.0f; + public float AccumulationAddedPerFrame = 1.0f / 3.0f; + public float MinDisocclusionAccumulation = -1.0f / 3.0f; public DispatchFlags Flags; public bool UseTextureArrays; // Enable texture array bindings, primarily used for HDRP and XR @@ -269,7 +273,12 @@ namespace FidelityFX.FSR3 public float frameIndex; public Vector2Int inputResourceSize; // WW1MOD + public float velocityFactor; + public float reactivenessScale; + public float shadingChangeScale; + public float accumulationAddedPerFrame; + public float minDisocclusionAccumulation; } [Serializable, StructLayout(LayoutKind.Sequential)] diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Runtime/FSR3/Fsr3UpscalerContext.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Runtime/FSR3/Fsr3UpscalerContext.cs index e8775667..a2a3ced3 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Runtime/FSR3/Fsr3UpscalerContext.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Runtime/FSR3/Fsr3UpscalerContext.cs @@ -97,6 +97,10 @@ namespace FidelityFX.FSR3 UpscalerConsts.maxUpscaleSize = _contextDescription.MaxUpscaleSize; UpscalerConsts.velocityFactor = 1.0f; + UpscalerConsts.reactivenessScale = 1.0f; + UpscalerConsts.shadingChangeScale = 1.0f; + UpscalerConsts.accumulationAddedPerFrame = 1.0f / 3.0f; + UpscalerConsts.minDisocclusionAccumulation = -1.0f / 3.0f; _resources.Create(_contextDescription); CreatePasses(); @@ -418,6 +422,10 @@ namespace FidelityFX.FSR3 constants.frameIndex += 1.0f; constants.velocityFactor = dispatchParams.VelocityFactor; + constants.reactivenessScale = dispatchParams.ReactivenessScale; + constants.shadingChangeScale = dispatchParams.ShadingChangeScale; + constants.accumulationAddedPerFrame = dispatchParams.AccumulationAddedPerFrame; + constants.minDisocclusionAccumulation = dispatchParams.MinDisocclusionAccumulation; } private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr3Upscaler.DispatchDescription dispatchParams) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h index 73b5ad69..3cb83332 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h @@ -1,7 +1,7 @@ // This file is part of the FidelityFX SDK. // // Copyright (C) 2024 Advanced Micro Devices, Inc. -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files(the "Software"), to deal // in the Software without restriction, including without limitation the rights @@ -46,13 +46,13 @@ void RectifyHistory( FFX_PARAMETER_INOUT AccumulationPassData data ) { - const FfxFloat32 fVecolityFactor = ffxSaturate(params.f4KVelocity / 20.0f); + const FfxFloat32 f4kVelocityFactor = ffxSaturate(params.f4KVelocity / 20.0f); const FfxFloat32 fDistanceFactor = ffxSaturate(0.75f - params.fFarthestDepthInMeters / 20.0f); const FfxFloat32 fAccumulationFactor = 1.0f - params.fAccumulation; const FfxFloat32 fReactiveFactor = ffxPow(params.fReactiveMask, 1.0f / 2.0f); const FfxFloat32 fShadingChangeFactor = params.fShadingChange; - const FfxFloat32 fBoxScaleT = ffxMax(fVecolityFactor, ffxMax(fDistanceFactor, ffxMax(fAccumulationFactor, ffxMax(fReactiveFactor, fShadingChangeFactor)))); - + const FfxFloat32 fBoxScaleT = ffxMax(f4kVelocityFactor, ffxMax(fDistanceFactor, ffxMax(fAccumulationFactor, ffxMax(fReactiveFactor, fShadingChangeFactor)))); + const FfxFloat32 fBoxScale = ffxLerp(3.0f, 1.0f, fBoxScaleT); const FfxFloat32x3 fScaledBoxVec = data.clippingBox.boxVec * FfxFloat32x3(1.7f, 1.0f, 1.0f) * fBoxScale; @@ -148,7 +148,7 @@ void Accumulate(FfxInt32x2 iPxHrPos) if (params.bIsExistingSample && !params.bIsNewSample) { ReprojectHistoryColor(params, data); } - + UpdateLockStatus(params, data); ComputeBaseAccumulationWeight(params, data); diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h index 986209e9..ffe3e63f 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h @@ -1,7 +1,7 @@ -// This file is part of the FidelityFX SDK. +// This file is part of the FidelityFX SDK. // // Copyright (C) 2024 Advanced Micro Devices, Inc. -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files(the "Software"), to deal // in the Software without restriction, including without limitation the rights @@ -77,7 +77,12 @@ cbuffer cbFSR3Upscaler : FFX_FSR3UPSCALER_DECLARE_CB(FSR3UPSCALER_BIND_CB_FSR3UP FfxFloat32 fFrameIndex; FfxInt32x2 iInputResourceSize; // WW1MOD + FfxFloat32 fVelocityFactor; + FfxFloat32 fReactivenessScale; + FfxFloat32 fShadingChangeScale; + FfxFloat32 fAccumulationAddedPerFrame; + FfxFloat32 fMinDisocclusionAccumulation; }; #define FFX_FSR3UPSCALER_CONSTANT_BUFFER_1_SIZE (sizeof(cbFSR3Upscaler) / 4) // Number of 32-bit values. This must be kept in sync with the cbFSR3Upscaler size. @@ -185,6 +190,16 @@ FfxFloat32 VelocityFactor() return fVelocityFactor; } +FfxFloat32 AccumulationAddedPerFrame() +{ + return fAccumulationAddedPerFrame; +} + +FfxFloat32 MinDisocclusionAccumulation() +{ + return fMinDisocclusionAccumulation; +} + #endif // #if defined(FSR3UPSCALER_BIND_CB_FSR3UPSCALER) #define FFX_FSR3UPSCALER_ROOTSIG_STRINGIFY(p) FFX_FSR3UPSCALER_ROOTSIG_STR(p) @@ -392,7 +407,7 @@ UNITY_FSR_TEX2D(FfxFloat32) r_reactive_mask : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3U FfxFloat32 LoadReactiveMask(FfxUInt32x2 iPxPos) { - return r_reactive_mask[UNITY_FSR_POS(iPxPos)]; + return r_reactive_mask[UNITY_FSR_POS(iPxPos)] * fReactivenessScale; } FfxInt32x2 GetReactiveMaskResourceDimensions() @@ -406,7 +421,7 @@ FfxInt32x2 GetReactiveMaskResourceDimensions() FfxFloat32 SampleReactiveMask(FfxFloat32x2 fUV) { - return r_reactive_mask.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).x; + return r_reactive_mask.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).x * fReactivenessScale; } #endif @@ -501,7 +516,7 @@ FfxFloat32x4 SampleLumaHistory(FfxFloat32x2 fUV) } #endif -#if defined(FSR3UPSCALER_BIND_SRV_RCAS_INPUT) +#if defined(FSR3UPSCALER_BIND_SRV_RCAS_INPUT) Texture2D r_rcas_input : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_RCAS_INPUT); FfxFloat32x4 LoadRCAS_Input(FfxInt32x2 iPxPos) @@ -562,12 +577,12 @@ Texture2D r_shading_change : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCAL FfxFloat32 LoadShadingChange(FfxUInt32x2 iPxPos) { - return r_shading_change[iPxPos]; + return r_shading_change[iPxPos] * fShadingChangeScale; } FfxFloat32 SampleShadingChange(FfxFloat32x2 fUV) { - return r_shading_change.SampleLevel(s_LinearClamp, fUV, 0); + return r_shading_change.SampleLevel(s_LinearClamp, fUV, 0) * fShadingChangeScale; } #endif diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_prepare_reactivity.h b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_prepare_reactivity.h index fa9571d6..ae24545c 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_prepare_reactivity.h +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR/Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_prepare_reactivity.h @@ -210,15 +210,28 @@ FfxFloat32 UpdateAccumulation(FfxInt32x2 iPxPos, FfxFloat32x2 fUv, FfxFloat32x2 const FfxFloat32x2 fReprojectedUv_HW = ClampUv(fReprojectedUv, PreviousFrameRenderSize(), MaxRenderSize()); fAccumulation = ffxSaturate(SampleAccumulation(fReprojectedUv_HW)); } + const FfxFloat32 fAccumulationAddedPerFrame= AccumulationAddedPerFrame(); //default is 0.333 + // Assume at frame N+0 fShadingChange is 1.0, and all subsequent frames fShadingChange is 0.0 and fDisocclusion is 0.0. Then, + // frame N+0 fAccumulation will be 0.000 + // frame N+2 fAccumulation will be 0.000 + 0.333 * 1 == 0.333 + // frame N+3 fAccumulation will be 0.000 + 0.333 * 2 == 0.666 + // frame N+4 fAccumulation will be 0.000 + 0.333 * 3 == 0.999 fAccumulation = ffxLerp(fAccumulation, 0.0f, fShadingChange); - fAccumulation = ffxLerp(fAccumulation, ffxMin(fAccumulation, 0.25f), fDisocclusion); + + const FfxFloat32 fMinDisocclusionAccumulation = MinDisocclusionAccumulation(); //default is -0.333 + // Assume at frame N+0 fDisocclusion is 1.0, and all subsequent frames fShadingChange is 0.0 and fDisocclusion is 0.0. Then, + // frame N+0 fAccumulation will be -0.333f (but normalized to store in unorm) + // frame N+1 fAccumulation will be -0.333f + 0.333 * 1 == 0.000 + // frame N+2 fAccumulation will be -0.333f + 0.333 * 2 == 0.333 + // frame N+3 fAccumulation will be -0.333f + 0.333 * 3 == 0.666 + // frame N+4 fAccumulation will be -0.333f + 0.333 * 4 == 0.999 + fAccumulation = ffxLerp(fAccumulation, ffxMin(fMinDisocclusionAccumulation, fAccumulation), fDisocclusion); fAccumulation *= FfxFloat32(round(fAccumulation * 100.0f) > 1.0f); // Update for next frame, normalize to store in unorm - const FfxFloat32 fAccumulatedFramesMax = 3.0f; - const FfxFloat32 fAccumulatedFramesToStore = ffxSaturate(fAccumulation + (1.0f / fAccumulatedFramesMax)); + const FfxFloat32 fAccumulatedFramesToStore = ffxSaturate(fAccumulation + fAccumulationAddedPerFrame); StoreAccumulation(iPxPos, fAccumulatedFramesToStore); return fAccumulation;