diff --git a/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/HDRenderPipeline.FidelityFX.Cacao.cs b/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/HDRenderPipeline.FidelityFX.Cacao.cs index dffcd2f5..4f8a253b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/HDRenderPipeline.FidelityFX.Cacao.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/HDRenderPipeline.FidelityFX.Cacao.cs @@ -7,6 +7,8 @@ namespace UnityEngine.Rendering.HighDefinition public partial class HDRenderPipeline { private CacaoContext m_CacaoContext; + private Vector2Int m_CacaoPrevResolution; + private bool m_CacaoPrevDownsample; class RenderCacaoParameters { @@ -47,17 +49,25 @@ namespace UnityEngine.Rendering.HighDefinition bilateralUpscale = runtimeShaders.cacaoBilateralUpscale, reinterleave = runtimeShaders.cacaoReinterleave, }); + } + // Detect changes in resolution parameters and reinitialize context if necessary + if (parameters.resolution.x != m_CacaoPrevResolution.x || parameters.resolution.y != m_CacaoPrevResolution.y || parameters.downsample != m_CacaoPrevDownsample) + { + m_CacaoContext.DestroyScreenSizeDependentResources(); + m_CacaoContext.InitScreenSizeDependentResources(new Cacao.ScreenSizeInfo { Width = (uint)parameters.resolution.x, Height = (uint)parameters.resolution.y, UseDownsampledSsao = parameters.downsample, }); + + m_CacaoPrevResolution = parameters.resolution; + m_CacaoPrevDownsample = parameters.downsample; } // TODO: init m_CacaoContext with data from parameters - // TODO: detect changes in parameters and reinit m_CacaoContext if necessary m_CacaoContext.UpdateSettings(parameters.settings); using (var builder = renderGraph.AddRenderPass("FidelityFX CACAO", out var passData, ProfilingSampler.Get(HDProfileId.AmbientOcclusion))) diff --git a/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/ffx_cacao_common_hdrp.cginc b/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/ffx_cacao_common_hdrp.cginc index eb42dc62..ff397a7a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/ffx_cacao_common_hdrp.cginc +++ b/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/ffx_cacao_common_hdrp.cginc @@ -44,6 +44,16 @@ float4 FFX_CACAO_Prepare_GatherDepthOffset(float2 uv, int2 offset) return _CameraDepthTexture.GatherRed(s_point_clamp_sampler, UV_TEXTURE2D_X(uv), offset); } +float4 FFX_CACAO_BilateralUpscale_LoadDepths(int2 coord) +{ + float4 depths; + depths.x = _CameraDepthTexture.Load(COORD_TEXTURE2D_X_LOD(coord, 0), int2(0, 0)).r; + depths.y = _CameraDepthTexture.Load(COORD_TEXTURE2D_X_LOD(coord, 0), int2(1, 0)).r; + depths.z = _CameraDepthTexture.Load(COORD_TEXTURE2D_X_LOD(coord, 0), int2(0, 1)).r; + depths.w = _CameraDepthTexture.Load(COORD_TEXTURE2D_X_LOD(coord, 0), int2(1, 1)).r; + return depths; +} + float3 LoadSceneNormals(int2 coord) { NormalData normalData; diff --git a/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/shaders/cacao/ffx_cacao_callbacks_hlsl.h b/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/shaders/cacao/ffx_cacao_callbacks_hlsl.h index 92f3219f..5486c288 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/shaders/cacao/ffx_cacao_callbacks_hlsl.h +++ b/com.unity.render-pipelines.high-definition/Runtime/FidelityFX/shaders/cacao/ffx_cacao_callbacks_hlsl.h @@ -858,19 +858,19 @@ FfxFloat32x2 FFX_CACAO_BilateralUpscale_LoadSSAO(FfxUInt32x2 coord, FfxUInt32 in #endif } -FfxFloat32x4 FFX_CACAO_BilateralUpscale_LoadDepths(FfxUInt32x2 coord) -{ - FfxFloat32x4 depths; -#if defined CACAO_BIND_SRV_DEPTH_IN - depths.x = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(0, 0)); - depths.y = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(1, 0)); - depths.z = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(0, 1)); - depths.w = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(1, 1)); - return depths; -#else - return FfxFloat32x4(0, 0, 0, 0); -#endif -} +// FfxFloat32x4 FFX_CACAO_BilateralUpscale_LoadDepths(FfxUInt32x2 coord) +// { +// FfxFloat32x4 depths; +// #if defined CACAO_BIND_SRV_DEPTH_IN +// depths.x = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(0, 0)); +// depths.y = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(1, 0)); +// depths.z = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(0, 1)); +// depths.w = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(1, 1)); +// return depths; +// #else +// return FfxFloat32x4(0, 0, 0, 0); +// #endif +// } FfxFloat32 FFX_CACAO_BilateralUpscale_LoadDownscaledDepth(FfxUInt32x2 coord, FfxUInt32 index) {