From 377f043ded2ca917818264eceb80c16dbec6e347 Mon Sep 17 00:00:00 2001 From: Pixelflinger Date: Thu, 17 Sep 2020 23:36:14 -0700 Subject: [PATCH] smooth out the transition from the background layer This is a bit of a hack but it helps a lot -- for some reason the background layer often has a sharp transition to the in-focus plane and because we're calculating the DoF at 1/4 resolution these transitions are quite visible. We work around this by fading out the transition over a 1 CoC unit, specifically between a CoC of 2 to 1 pixel. Below 1 pixel, we currently clamp to 0. --- filament/src/materials/dof/dof.mat | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/filament/src/materials/dof/dof.mat b/filament/src/materials/dof/dof.mat index 0e609c9e06..8ded8f50ba 100644 --- a/filament/src/materials/dof/dof.mat +++ b/filament/src/materials/dof/dof.mat @@ -529,6 +529,11 @@ void postProcess(inout PostProcessInputs postProcess) { background = prev.c; bgOpacity = cocToAlpha(prev.coc); +#if defined(TARGET_MOBILE) + bgOpacity *= saturate((kernelSize - MAX_IN_FOCUS_COC) / (2.0 - MAX_IN_FOCUS_COC)); +#else + bgOpacity *= smoothstep(MAX_IN_FOCUS_COC, 2.0, kernelSize); +#endif if (prev.cw < MEDIUMP_FLT_MIN) { background *= 0.0;