From c838506b07c0e369adfdcee375e1cef1fe609917 Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Tue, 21 Apr 2020 20:21:13 +0100 Subject: [PATCH] depth of field update --- WickedEngine/depthoffieldHF.hlsli | 4 ++++ WickedEngine/depthoffield_neighborhoodMaxCOCCS.hlsl | 5 ++--- WickedEngine/depthoffield_prepassCS.hlsl | 3 +-- WickedEngine/depthoffield_tileMaxCOC_horizontalCS.hlsl | 3 ++- WickedEngine/depthoffield_upsampleCS.hlsl | 9 ++++++--- WickedEngine/wiVersion.cpp | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/WickedEngine/depthoffieldHF.hlsli b/WickedEngine/depthoffieldHF.hlsli index 9d5b0bb51..54afe2b0d 100644 --- a/WickedEngine/depthoffieldHF.hlsli +++ b/WickedEngine/depthoffieldHF.hlsli @@ -1,6 +1,10 @@ #ifndef WI_DEPTHOFFIELD_HF #define WI_DEPTHOFFIELD_HF +inline float get_coc(in float linear_depth) +{ + return min(dof_maxcoc, dof_scale * pow(abs(1 - dof_focus / (linear_depth * g_xCamera_ZFarP)), 2.0f)); +} #define DOF_DEPTH_SCALE_FOREGROUND (g_xCamera_ZFarP * 1.5) float2 DepthCmp2(float depth, float closestTileDepth) diff --git a/WickedEngine/depthoffield_neighborhoodMaxCOCCS.hlsl b/WickedEngine/depthoffield_neighborhoodMaxCOCCS.hlsl index cedecb892..f15175c09 100644 --- a/WickedEngine/depthoffield_neighborhoodMaxCOCCS.hlsl +++ b/WickedEngine/depthoffield_neighborhoodMaxCOCCS.hlsl @@ -42,9 +42,8 @@ void main(uint3 DTid : SV_DispatchThreadID) { tile_statistics.InterlockedAdd(TILE_STATISTICS_OFFSET_EARLYEXIT, 1, prevCount); tiles_earlyexit[prevCount] = tile; - return; } - else if (abs(max_coc - min_coc) < 0.1f) + else if (abs(max_coc - min_coc) < 1) { tile_statistics.InterlockedAdd(TILE_STATISTICS_OFFSET_CHEAP, 1, prevCount); tiles_cheap[prevCount] = tile; @@ -54,5 +53,5 @@ void main(uint3 DTid : SV_DispatchThreadID) tile_statistics.InterlockedAdd(TILE_STATISTICS_OFFSET_EXPENSIVE, 1, prevCount); tiles_expensive[prevCount] = tile; } - output[DTid.xy] = float2(min_depth, min(dof_maxcoc, max_coc)); + output[DTid.xy] = float2(min_depth, max_coc); } \ No newline at end of file diff --git a/WickedEngine/depthoffield_prepassCS.hlsl b/WickedEngine/depthoffield_prepassCS.hlsl index cab6ff12d..ec51b7db7 100644 --- a/WickedEngine/depthoffield_prepassCS.hlsl +++ b/WickedEngine/depthoffield_prepassCS.hlsl @@ -32,7 +32,7 @@ void main(uint3 Gid : SV_GroupID, uint3 GTid : SV_GroupThreadID) const float mindepth = neighborhood_mindepth_maxcoc[2 * pixel / DEPTHOFFIELD_TILESIZE].x; const float center_depth = texture_lineardepth.Load(uint3(pixel, 1)); - const float coc = min(dof_maxcoc, dof_scale * abs(1 - dof_focus / (center_depth * g_xCamera_ZFarP))); + const float coc = get_coc(center_depth); const float alpha = SampleAlpha(coc); const float2 depthcmp = DepthCmp2(center_depth, mindepth); @@ -53,7 +53,6 @@ void main(uint3 Gid : SV_GroupID, uint3 GTid : SV_GroupThreadID) [unroll] for (uint i = ringSampleCount[0]; i < ringSampleCount[1]; ++i) { - const float offsetCoc = disc[i].z; const float2 uv2 = uv + ringScale * disc[i].xy; const float depth = texture_lineardepth.SampleLevel(sampler_point_clamp, uv2, 1); const float3 color = max(0, input.SampleLevel(sampler_linear_clamp, uv2, 0).rgb); diff --git a/WickedEngine/depthoffield_tileMaxCOC_horizontalCS.hlsl b/WickedEngine/depthoffield_tileMaxCOC_horizontalCS.hlsl index ac3bb6359..85b08e0e7 100644 --- a/WickedEngine/depthoffield_tileMaxCOC_horizontalCS.hlsl +++ b/WickedEngine/depthoffield_tileMaxCOC_horizontalCS.hlsl @@ -1,5 +1,6 @@ #include "globals.hlsli" #include "ShaderInterop_Postprocess.h" +#include "depthOfFieldHF.hlsli" RWTEXTURE2D(tile_mindepth_maxcoc, float2, 0); RWTEXTURE2D(tile_mincoc, float, 1); @@ -22,7 +23,7 @@ void main(uint3 DTid : SV_DispatchThreadID) if (pixel.x >= 0 && pixel.y >= 0 && pixel.x < dim.x && pixel.y < dim.y) { const float depth = texture_lineardepth[pixel]; - const float coc = dof_scale * abs(1 - dof_focus / (depth * g_xCamera_ZFarP)); + const float coc = get_coc(depth); min_depth = min(min_depth, depth); max_coc = max(max_coc, coc); min_coc = min(min_coc, coc); diff --git a/WickedEngine/depthoffield_upsampleCS.hlsl b/WickedEngine/depthoffield_upsampleCS.hlsl index 984f5bcca..3b3cb0fc0 100644 --- a/WickedEngine/depthoffield_upsampleCS.hlsl +++ b/WickedEngine/depthoffield_upsampleCS.hlsl @@ -22,19 +22,22 @@ void main(uint3 DTid : SV_DispatchThreadID) const float3 halfres = texture_postfilter.SampleLevel(sampler_linear_clamp, uv, 0); const float alpha = texture_alpha.SampleLevel(sampler_linear_clamp, uv, 0); - const float coc = min(dof_maxcoc, dof_scale * abs(1 - dof_focus / (center_depth * g_xCamera_ZFarP))); + const float coc = get_coc(center_depth); - float depthDelta = saturate(1.0 - g_xCamera_ZFarP * 0.2 * (center_depth - mindepth)); + float depthDelta = saturate(1.0 - g_xCamera_ZFarP * (center_depth - mindepth)); const float backgroundFactor = coc; - const float foregroundFactor = lerp(maxcoc, coc, pow(depthDelta, 1.0f / 2.2f)); + const float foregroundFactor = lerp(maxcoc, coc, depthDelta); const float combinedFactor = saturate(lerp(backgroundFactor, foregroundFactor, alpha)); float4 color = float4(lerp(fullres.rgb, halfres, combinedFactor), fullres.a); //color = backgroundFactor; //color = foregroundFactor; + //color = maxcoc; //color = combinedFactor; + //color = alpha; + //color = depthDelta; //color.rgb = halfres; //if (coc < 0.01) color = float4(1, 0, 0, 1); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index c83505d09..783c3f69e 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 39; // minor bug fixes, alterations, refactors, updates - const int revision = 75; + const int revision = 76; long GetVersion()