Workbench: Fix depth of field background being glitchy

This commit is contained in:
Clément Foucault 2020-02-13 01:54:59 +01:00
parent 10b04fa316
commit eaea5c8904
2 changed files with 16 additions and 8 deletions

View File

@ -251,7 +251,7 @@ void main()
ivec2 texel = ivec2(uv * size);
vec4 color = vec4(0.0);
float tot = 1e-4;
float tot = 0.0;
float coc = decode_coc(texelFetch(inputCocTex, texel, 0).rg);
float max_radius = coc;
@ -272,7 +272,12 @@ void main()
tot += weight;
}
blurColor = color / tot;
if (tot > 0.0) {
blurColor = color / tot;
}
else {
blurColor = textureLod(halfResColorTex, uv, 0.0);
}
}
#endif
@ -385,7 +390,9 @@ void main()
* ----------------- STEP 4 ------------------
*/
#ifdef RESOLVE
out vec4 finalColor;
layout(location = 0) out vec4 finalColorAdd;
layout(location = 1) out vec4 finalColorMul;
void main()
{
@ -398,7 +405,8 @@ void main()
float zdepth = linear_depth(depth);
float coc = calculate_coc(zdepth);
finalColor = texture(halfResColorTex, uv);
finalColor.a = smoothstep(1.0, 3.0, abs(coc));
float blend = smoothstep(1.0, 3.0, abs(coc));
finalColorAdd = texture(halfResColorTex, uv) * blend;
finalColorMul = vec4(1.0 - blend);
}
#endif

View File

@ -181,11 +181,11 @@ void workbench_dof_engine_init(WORKBENCH_Data *vedata, Object *camera)
#endif
DRW_texture_ensure_2d(
&txl->dof_source_tx, size[0], size[1], GPU_R11F_G11F_B10F, DRW_TEX_FILTER | DRW_TEX_MIPMAP);
&txl->dof_source_tx, size[0], size[1], GPU_RGBA16F, DRW_TEX_FILTER | DRW_TEX_MIPMAP);
DRW_texture_ensure_2d(
&txl->coc_halfres_tx, size[0], size[1], GPU_RG8, DRW_TEX_FILTER | DRW_TEX_MIPMAP);
wpd->dof_blur_tx = DRW_texture_pool_query_2d(
size[0], size[1], GPU_R11F_G11F_B10F, &draw_engine_workbench_solid);
size[0], size[1], GPU_RGBA16F, &draw_engine_workbench_solid);
#if 0
wpd->coc_temp_tx = DRW_texture_pool_query_2d(
shrink_h_size[0], shrink_h_size[1], GPU_RG8, &draw_engine_workbench_solid);
@ -299,7 +299,7 @@ void workbench_dof_create_pass(WORKBENCH_Data *vedata,
psl->dof_blur1_ps = DRW_pass_create("DoF Blur 1", DRW_STATE_WRITE_COLOR);
psl->dof_blur2_ps = DRW_pass_create("DoF Blur 2", DRW_STATE_WRITE_COLOR);
psl->dof_resolve_ps = DRW_pass_create("DoF Resolve",
DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA);
DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM);
{
DRWShadingGroup *grp = DRW_shgroup_create(e_data.effect_dof_prepare_sh, psl->dof_down_ps);