Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-10-15 17:04:33 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-10-15 17:04:50 +0300
commit9ecf68e8ae060c8d46a809ca3e6aacf399f23033 (patch)
tree2ae014c7815366e1118fce2941231a9c8bb1dc54 /source/blender/draw/engines/eevee/shaders
parent478899dee771e2421d49077674af4de97b78cd9e (diff)
Eevee: Fix Missing alpha when rendering with DOF
NOTE: There is a float imprecision near the focus plane due to the current technique used for DOF. This makes the alpha channel transparent on nearly in focus objects even when they should not. This artifact should be fixed when the DOF will use scatter as gather for low brightness areas. Fix T57042 : Eevee does not render alpha when DOF is turned on
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders')
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl40
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl5
2 files changed, 38 insertions, 7 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl
index d816d72c1e3..27517ebd86e 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl
@@ -77,6 +77,14 @@ void main(void)
vec4 near_weights = step(THRESHOLD, coc_near) * clamp(1.0 - abs(cocData.x - coc_near), 0.0, 1.0);
vec4 far_weights = step(THRESHOLD, coc_far) * clamp(1.0 - abs(cocData.y - coc_far), 0.0, 1.0);
+# ifdef USE_ALPHA_DOF
+ /* Premult */
+ color1.rgb *= color1.a;
+ color2.rgb *= color2.a;
+ color3.rgb *= color3.a;
+ color4.rgb *= color4.a;
+# endif
+
/* now write output to weighted buffers. */
nearColor = weighted_sum(color1, color2, color3, color4, near_weights);
farColor = weighted_sum(color1, color2, color3, color4, far_weights);
@@ -85,12 +93,16 @@ void main(void)
#elif defined(STEP_SCATTER)
flat in vec4 color;
+flat in float weight;
flat in float smoothFac;
flat in ivec2 edge;
/* coordinate used for calculating radius */
in vec2 particlecoord;
-out vec4 fragColor;
+layout(location = 0) out vec4 fragColor;
+# ifdef USE_ALPHA_DOF
+layout(location = 1) out float fragAlpha;
+# endif
/* accumulate color in the near/far blur buffers */
void main(void)
@@ -130,9 +142,14 @@ void main(void)
/* Smooth the edges a bit. This effectively reduce the bokeh shape
* but does fade out the undersampling artifacts. */
- if (smoothFac < 1.0) {
- fragColor *= smoothstep(1.0, smoothFac, dist);
- }
+ float shape = smoothstep(1.0, min(0.999, smoothFac), dist);
+
+ fragColor *= shape;
+
+# ifdef USE_ALPHA_DOF
+ fragAlpha = fragColor.a;
+ fragColor.a = weight * shape;
+# endif
}
#elif defined(STEP_RESOLVE)
@@ -140,6 +157,7 @@ void main(void)
#define MERGE_THRESHOLD 4.0
uniform sampler2D scatterBuffer;
+uniform sampler2D scatterAlphaBuffer;
in vec4 uvcoordsvar;
out vec4 fragColor;
@@ -203,9 +221,21 @@ void main(void)
float far_w = far_col.a;
float near_w = near_col.a;
float focus_w = 1.0 - smoothstep(1.0, MERGE_THRESHOLD, abs(coc_signed));
+ float inv_weight_sum = 1.0 / (near_w + focus_w + far_w);
+
focus_col *= focus_w; /* Premul */
- fragColor = (far_col + near_col + focus_col) / (near_w + focus_w + far_w);
+# ifdef USE_ALPHA_DOF
+ near_col.a = upsample_filter(scatterAlphaBuffer, near_uv, texelSize).r;
+ far_col.a = upsample_filter(scatterAlphaBuffer, far_uv, texelSize).r;
+# endif
+
+ fragColor = (far_col + near_col + focus_col) * inv_weight_sum;
+
+# ifdef USE_ALPHA_DOF
+ /* Unpremult */
+ fragColor.rgb /= (fragColor.a > 0.0) ? fragColor.a : 1.0;
+# endif
}
#endif
diff --git a/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl b/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl
index ec8b474b431..92fd36f684a 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl
@@ -10,6 +10,7 @@ uniform sampler2D farBuffer;
uniform sampler2D cocBuffer;
flat out vec4 color;
+flat out float weight;
flat out float smoothFac;
flat out ivec2 edge;
out vec2 particlecoord;
@@ -49,8 +50,8 @@ void main()
/* find the area the pixel will cover and divide the color by it */
/* HACK: 4.0 out of nowhere (I suppose it's 4 pixels footprint for coc 0?)
* Makes near in focus more closer to 1.0 alpha. */
- color.a = 4.0 / (coc * coc * M_PI);
- color.rgb *= color.a;
+ weight = 4.0 / (coc * coc * M_PI);
+ color *= weight;
/* Compute edge to discard fragment that does not belong to the other layer. */
edge.x = (is_near) ? 1 : -1;