From b44b8955b39d930afe34fe082bce77f9057e0839 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Tue, 7 Dec 2021 15:54:27 +0100 Subject: [PATCH] Fix depth of field blur artifacts on upper and left screen edges --- Content/Shaders/DepthOfField.flax | 4 ++-- Source/Shaders/DepthOfField.shader | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Content/Shaders/DepthOfField.flax b/Content/Shaders/DepthOfField.flax index 6c4d9daec..bd13f9e5e 100644 --- a/Content/Shaders/DepthOfField.flax +++ b/Content/Shaders/DepthOfField.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d8b69fce536cb27d497f6ff91f8adff3fbeaa9a704ced1b3271f4d621c195d53 -size 21054 +oid sha256:a454773300cfbe43a9dec0503108edd9fc0e3686078beb6b3827ddb1524143a5 +size 21078 diff --git a/Source/Shaders/DepthOfField.shader b/Source/Shaders/DepthOfField.shader index f8753bbba..cf4cdb1cc 100644 --- a/Source/Shaders/DepthOfField.shader +++ b/Source/Shaders/DepthOfField.shader @@ -137,11 +137,11 @@ META_CS(true, FEATURE_LEVEL_SM5) void CS_DepthOfFieldH(uint3 groupID : SV_GroupID, uint3 groupThreadID : SV_GroupThreadID) { // These positions are relative to the "grid", AKA the horizontal group of pixels that this thread group is writing to - const uint gridStartX = groupID.x * DOF_GRID_SIZE; - const uint gridX = groupThreadID.x - DOF_APRON_SIZE; + const int gridStartX = groupID.x * DOF_GRID_SIZE; + const int gridX = groupThreadID.x - DOF_APRON_SIZE; // These positions are relative to the pixel coordinates - const uint sampleX = gridStartX + gridX; + const uint sampleX = max(gridStartX + gridX, 0); const uint sampleY = groupID.y; uint2 textureSize; @@ -218,12 +218,12 @@ META_CS(true, FEATURE_LEVEL_SM5) void CS_DepthOfFieldV(uint3 groupID : SV_GroupID, uint3 groupThreadID : SV_GroupThreadID) { // These positions are relative to the "grid", AKA the vertical group of pixels that this thread group is writing to - const uint gridStartY = groupID.y * DOF_GRID_SIZE; - const uint gridY = groupThreadID.y - DOF_APRON_SIZE; + const int gridStartY = groupID.y * DOF_GRID_SIZE; + const int gridY = groupThreadID.y - DOF_APRON_SIZE; // These positions are relative to the pixel coordinates const uint sampleX = groupID.x; - const uint sampleY = gridStartY + gridY; + const uint sampleY = max(gridStartY + gridY, 0); uint2 textureSize; Input0.GetDimensions(textureSize.x, textureSize.y); @@ -311,11 +311,11 @@ META_CS(true, FEATURE_LEVEL_SM5) void CS_CoCSpreadH(uint3 groupID : SV_GroupID, uint3 groupThreadID : SV_GroupThreadID) { // These positions are relative to the "grid", AKA the horizontal group of pixels that this thread group is writing to - const uint gridStartX = groupID.x * DOF_GRID_SIZE; - const uint gridX = groupThreadID.x - DOF_APRON_SIZE; + const int gridStartX = groupID.x * DOF_GRID_SIZE; + const int gridX = groupThreadID.x - DOF_APRON_SIZE; // These positions are relative to the pixel coordinates - const uint sampleX = gridStartX + gridX; + const uint sampleX = max(gridStartX + gridX, 0); const uint sampleY = groupID.y; uint2 textureSize; @@ -382,12 +382,12 @@ META_CS(true, FEATURE_LEVEL_SM5) void CS_CoCSpreadV(uint3 groupID : SV_GroupID, uint3 groupThreadID : SV_GroupThreadID) { // These positions are relative to the "grid", AKA the vertical group of pixels that this thread group is writing to - const uint gridStartY = groupID.y * DOF_GRID_SIZE; - const uint gridY = groupThreadID.y - DOF_APRON_SIZE; + const int gridStartY = groupID.y * DOF_GRID_SIZE; + const int gridY = groupThreadID.y - DOF_APRON_SIZE; // These positions are relative to the pixel coordinates const uint sampleX = groupID.x; - const uint sampleY = gridStartY + gridY; + const uint sampleY = max(gridStartY + gridY, 0); uint2 textureSize; Input0.GetDimensions(textureSize.x, textureSize.y);