From 29c2b385f4d841fbbf5c58472431b7b4194e97bb Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Fri, 19 Dec 2025 17:26:11 +0100 Subject: [PATCH] Auto-sync from SVN revision 69247 --- .../HDRenderPipeline.AmbientOcclusion.cs | 7 ++ .../ScreenSpaceAmbientOcclusion.cs | 1 + .../Shaders/AlphaUpscale.compute | 65 +++++++++++-------- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/HDRenderPipeline.AmbientOcclusion.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/HDRenderPipeline.AmbientOcclusion.cs index be1f8a69..cd6c1802 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/HDRenderPipeline.AmbientOcclusion.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/HDRenderPipeline.AmbientOcclusion.cs @@ -189,6 +189,13 @@ namespace UnityEngine.Rendering.HighDefinition result = RenderCacao(renderGraph, hdCamera, cacaoParameters, depthBuffer, normalBuffer); } + else if (settings.aoMode.value == ScreenSpaceAmbientOcclusion.AmbientOcclusionMode.HTRACE) //WW1MOD Added HTRACE + { + //We prevent about 28.8mb of RT's by not having HDRP create the history which we do not use, as HTrace has its own + var aoParameters = PrepareRenderAOParameters(hdCamera, new Vector2(hdCamera.actualWidth, hdCamera.actualHeight), depthMipInfo); + result = RenderAO(renderGraph, aoParameters, depthPyramid, normalBuffer); + result = SpatialDenoiseAO(renderGraph, aoParameters, result); + } else { m_AOHistoryReady = !hdCamera.AllocateAmbientOcclusionHistoryBuffer(settings.fullResolution ? 1.0f : 0.5f); diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceAmbientOcclusion.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceAmbientOcclusion.cs index d0b8b940..51d707b1 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceAmbientOcclusion.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceAmbientOcclusion.cs @@ -18,6 +18,7 @@ namespace UnityEngine.Rendering.HighDefinition { Default, Cacao, + HTRACE //Amplify, } diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/AlphaUpscale.compute b/Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/AlphaUpscale.compute index faa62ad9..242038a8 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/AlphaUpscale.compute +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/AlphaUpscale.compute @@ -1,5 +1,6 @@ #pragma kernel KMain #pragma kernel KUpscaleFromDepth +#pragma kernel KChromaKeyToAlpha #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch @@ -107,23 +108,6 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID) _OutputTexture[COORD_TEXTURE2D_X(InputPos)] = float4(fColor, fAlphaAccumulate); } -static const float3 fKeyColor = float3(0, 1, 0); // Green screen chroma key, this needs to match the camera's background color -static const float fToleranceA = 0.4f; -static const float fToleranceB = 0.49f; - -// Derived from http://gc-films.com/chromakey.html, using the faster YCoCg color space instead of YCbCr -float ChromaKey(float3 fColor) -{ - const float3 fColorYCoCg = RGBToYCoCg(fColor); - const float3 fKeyYCoCg = RGBToYCoCg(fKeyColor); - - const float3 fDelta = fKeyYCoCg - fColorYCoCg; - const float fDist = sqrt(fDelta.y * fDelta.y + fDelta.z * fDelta.z); - const float fMask = fDist < fToleranceA ? 0.0f : fDist < fToleranceB ? (fDist - fToleranceA) / (fToleranceB - fToleranceA) : 1.0f; - - return fMask; -} - [numthreads(8, 8, 1)] void KUpscaleFromDepth(uint3 dispatchThreadId : SV_DispatchThreadID) { @@ -146,19 +130,48 @@ void KUpscaleFromDepth(uint3 dispatchThreadId : SV_DispatchThreadID) const float2 fClampedLocation = max(0.5f, min(fSampleLocation, RenderSize - 0.5f)); const float2 fLrUv_HwSampler = fClampedLocation * InvInputResourceSize; - float3 fColor = _InputTexture[COORD_TEXTURE2D_X(InputPos)].rgb; - - // Derive alpha value from green screen chroma keying - const float fAlpha = ChromaKey(fColor); + // De-jittered and bilinear upscaled alpha from depth + const float fAlpha = Linear01Depth(SAMPLE_TEXTURE2D_X_LOD(_CameraDepthTexture, s_linear_clamp_sampler, fLrUv_HwSampler, 0).r, _ZBufferParams) < 1 ? 1.0 : 0.0; // Temporally reproject alpha from the previous frame and blend it with the current frame's upscaled alpha const DepthExtents depthExtents = FindDepthExtents(fHrUvhistory, RenderSize); // Dilate depth so we don't end up grabbing motion vectors from the background - const float2 fDilatedMotionVector = LOAD_TEXTURE2D_X(_CameraMotionVectorsTexture, depthExtents.fNearestCoord).xy; - const float fReprojectedAlphaHistory = SAMPLE_TEXTURE2D_X_LOD(_InputHistoryTexture, s_linear_clamp_sampler, fHrUvhistory - fDilatedMotionVector, 0).r; // Sample reprojected history //TODO WRONG UV - const float fVelocityFactor = saturate(length(fDilatedMotionVector * DisplaySize) / 2.0f); // Adjust the amount of temporal blending based on the amount of motion + const float2 fMotionVector = LOAD_TEXTURE2D_X(_CameraMotionVectorsTexture, depthExtents.fNearestCoord).xy; + const float fReprojectedAlphaHistory = SAMPLE_TEXTURE2D_X_LOD(_InputHistoryTexture, s_linear_clamp_sampler, fHrUvhistory - fMotionVector, 0).r; // Sample reprojected history //TODO WRONG UV + const float fVelocityFactor = saturate(length(fMotionVector * DisplaySize) / 2.0f); // Adjust the amount of temporal blending based on the amount of motion const float fBlend = depthExtents.fNearest > FLT_EPS && _TaaFrameInfo.z > 0 ? fVelocityFactor * 0.5f + 0.2f : 1.0f; // Depth clip to eliminate after-images const float fAlphaAccumulate = lerp(fReprojectedAlphaHistory, fAlpha, fBlend); - _OutputHistoryTexture[COORD_TEXTURE2D_X(InputPos)] = fAlphaAccumulate; - _OutputTexture2D[(InputPos)] = float4(fColor - (1.0f - fAlpha) * fKeyColor, fAlphaAccumulate); // Remove green spill from the edges + + const float3 fColor = _InputTexture[COORD_TEXTURE2D_X(InputPos)].rgb; + _OutputTexture2D[(InputPos)] = float4(fColor, fAlphaAccumulate); +} + +uniform float3 fKeyColor = float3(0, 1, 0); // Green screen chroma key, this needs to match the camera's background color +uniform float fToleranceA = 0.4f; +uniform float fToleranceB = 0.49f; + +// Derived from http://gc-films.com/chromakey.html, using the faster YCoCg color space instead of YCbCr +float ChromaKey(float3 fColor) +{ + const float3 fColorYCoCg = RGBToYCoCg(fColor); + const float3 fKeyYCoCg = RGBToYCoCg(fKeyColor); + + const float3 fDelta = fKeyYCoCg - fColorYCoCg; + const float fDist = sqrt(fDelta.y * fDelta.y + fDelta.z * fDelta.z); + const float fMask = fDist < fToleranceA ? 0.0f : fDist < fToleranceB ? (fDist - fToleranceA) / (fToleranceB - fToleranceA) : 1.0f; + + return fMask; +} + +[numthreads(8, 8, 1)] +void KChromaKeyToAlpha(uint3 dispatchThreadId : SV_DispatchThreadID) +{ + UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z); + + const uint2 InputPos = dispatchThreadId.xy; + + float3 fColor = _InputTexture[COORD_TEXTURE2D_X(InputPos)].rgb; + const float fAlpha = ChromaKey(fColor); + + _OutputTexture2D[(InputPos)] = float4(fColor - (1.0f - fAlpha) * fKeyColor, fAlpha); // Remove green spill from the edges }