diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-05-12 01:52:04 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-13 00:28:55 +0300 |
commit | 74a08cf12854308af166742f7dcaa5c7c227fcd4 (patch) | |
tree | cb3b7bcc24bb75d16f706317dcc987a4fb3e67b3 /source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl | |
parent | 894639f9a59c3a4f1ae1b3fb4ccbf1f46e31669c (diff) |
Eevee: Depth of field: Change final blending.
This new blending allows background to fill the gaps left by forground
objects. However this has a drawback, background objects that should be
partially occluded in this case can be seen through the blurred objects.
This does not fix the problem of blurred foreground over sharp background.
Also cleanup code to be simpler and remove unused geometry shader.
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl | 36 |
1 files changed, 9 insertions, 27 deletions
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 05f5eb78253..dc34f2bd1fc 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl @@ -1,7 +1,4 @@ -in vec2 pos; -in vec2 uvs; - uniform vec2 layerSelection; uniform vec4 bokehParams; @@ -19,8 +16,8 @@ out vec2 particlecoord; #define M_PI 3.1415926535897932384626433832795 -/* geometry shading pass, calculate a texture coordinate based on the indexed id */ -void step_scatter() +/* Scatter pass, calculate a triangle covering the CoC. */ +void main() { ivec2 tex_size = textureSize(cocBuffer, 0); vec2 texel_size = 1.0 / vec2(tex_size); @@ -32,7 +29,8 @@ void step_scatter() texelco.x = t_id % tex_size.x; texelco.y = t_id / tex_size.x; - float coc = dot(layerSelection, texelFetch(cocBuffer, texelco, 0).rg); + vec2 cocs = texelFetch(cocBuffer, texelco, 0).rg; + float coc = dot(layerSelection, cocs); /* Clamp to max size for performance */ coc = min(coc, bokeh_maxsize); @@ -40,12 +38,14 @@ void step_scatter() if (coc >= 1.0) { color = texelFetch(colorBuffer, texelco, 0); /* find the area the pixel will cover and divide the color by it */ - float alpha = 1.0 / (coc * coc * M_PI); - color *= alpha; - color.a = alpha; + color.a = 1.0 / (coc * coc * M_PI); + color.rgb *= color.a; } else { + /* Don't produce any fragments */ color = vec4(0.0); + gl_Position = vec4(0.0, 0.0, 0.0, 1.0); + return; } /* Generate Triangle : less memory fetches from a VBO */ @@ -77,23 +77,5 @@ void step_scatter() gl_Position.xy *= coc * texel_size * vec2(bokeh_ratio, 1.0); gl_Position.xy -= 1.0 - 0.5 * texel_size; /* NDC Bottom left */ gl_Position.xy += (0.5 + vec2(texelco) * 2.0) * texel_size; -} -out vec2 uvcoord; - -void passthrough() -{ - uvcoord = uvs; - gl_Position = vec4(pos, 0.0, 1.0); -} - -void main() -{ -#if defined(STEP_DOWNSAMPLE) - passthrough(); -#elif defined(STEP_SCATTER) - step_scatter(); -#elif defined(STEP_RESOLVE) - passthrough(); -#endif } |