GP: Fix several issues in blur FX
There were some problems with the z-depth and especially when tries to blur a pixel outside the viewport.
This commit is contained in:
parent
55e3c17ccc
commit
ac61eb3900
|
@ -218,6 +218,7 @@ static void DRW_gpencil_fx_blur(
|
|||
DRW_shgroup_call_add(fx_shgrp, fxquad, NULL);
|
||||
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeColor", &e_data->temp_color_tx_a);
|
||||
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_a);
|
||||
DRW_shgroup_uniform_vec2(fx_shgrp, "Viewport", DRW_viewport_size_get(), 1);
|
||||
DRW_shgroup_uniform_int(fx_shgrp, "blur", &fxd->blur[0], 2);
|
||||
|
||||
DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &cache->loc[0], 1);
|
||||
|
@ -409,6 +410,7 @@ static void DRW_gpencil_fx_rim(
|
|||
DRW_shgroup_call_add(fx_shgrp, fxquad, NULL);
|
||||
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeColor", &e_data->temp_color_tx_fx);
|
||||
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_fx);
|
||||
DRW_shgroup_uniform_vec2(fx_shgrp, "Viewport", DRW_viewport_size_get(), 1);
|
||||
DRW_shgroup_uniform_int(fx_shgrp, "blur", &fxd->blur[0], 2);
|
||||
|
||||
DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &cache->loc[0], 1);
|
||||
|
@ -493,6 +495,7 @@ static void DRW_gpencil_fx_shadow(
|
|||
DRW_shgroup_call_add(fx_shgrp, fxquad, NULL);
|
||||
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeColor", &e_data->temp_color_tx_fx);
|
||||
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_fx);
|
||||
DRW_shgroup_uniform_vec2(fx_shgrp, "Viewport", DRW_viewport_size_get(), 1);
|
||||
DRW_shgroup_uniform_int(fx_shgrp, "blur", &fxd->blur[0], 2);
|
||||
|
||||
DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &cache->loc[0], 1);
|
||||
|
@ -551,6 +554,7 @@ static void DRW_gpencil_fx_glow(
|
|||
DRW_shgroup_call_add(fx_shgrp, fxquad, NULL);
|
||||
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeColor", &e_data->temp_color_tx_fx);
|
||||
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_fx);
|
||||
DRW_shgroup_uniform_vec2(fx_shgrp, "Viewport", DRW_viewport_size_get(), 1);
|
||||
DRW_shgroup_uniform_int(fx_shgrp, "blur", &fxd->blur[0], 2);
|
||||
|
||||
DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &cache->loc[0], 1);
|
||||
|
|
|
@ -3,6 +3,7 @@ uniform mat4 ViewMatrix;
|
|||
|
||||
uniform sampler2D strokeColor;
|
||||
uniform sampler2D strokeDepth;
|
||||
uniform vec2 Viewport;
|
||||
|
||||
uniform int blur[2];
|
||||
|
||||
|
@ -15,6 +16,20 @@ vec2 noffset = vec2(blur[0], blur[1]);
|
|||
|
||||
out vec4 FragColor;
|
||||
|
||||
float get_zdepth(ivec2 poxy)
|
||||
{
|
||||
/* if outside viewport set as infinite depth */
|
||||
if ((poxy.x < 0) || (poxy.x > Viewport.x)) {
|
||||
return 1.0f;
|
||||
}
|
||||
if ((poxy.y < 0) || (poxy.y > Viewport.y)) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
float zdepth = texelFetch(strokeDepth, poxy, 0).r;
|
||||
return zdepth;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 uv = ivec2(gl_FragCoord.xy);
|
||||
|
@ -25,19 +40,20 @@ void main()
|
|||
float dy = (ProjectionMatrix[3][3] == 0.0) ? (noffset[1] / (nloc.z * defaultpixsize)) : (noffset[1] / defaultpixsize);
|
||||
|
||||
/* apply blurring, using a 9-tap filter with predefined gaussian weights */
|
||||
/* depth (get the minimum value of the surrounding pixels) */
|
||||
float outdepth = 0;
|
||||
outdepth = texelFetch(strokeDepth, ivec2(uv.x - 1.0 * dx, uv.y + 1.0 * dy), 0).r;
|
||||
outdepth = min(outdepth, texelFetch(strokeDepth, ivec2(uv.x - 0.0 * dx, uv.y + 1.0 * dy), 0).r);
|
||||
outdepth = min(outdepth, texelFetch(strokeDepth, ivec2(uv.x + 1.0 * dx, uv.y + 1.0 * dy), 0).r);
|
||||
outdepth = min(outdepth, texelFetch(strokeDepth, ivec2(uv.x - 1.0 * dx, uv.y + 0.0 * dy), 0).r);
|
||||
/* depth (get the value of the surrounding pixels) */
|
||||
float outdepth = 0.0;
|
||||
|
||||
outdepth += get_zdepth(ivec2(uv.x - 1.0 * dx, uv.y + 1.0 * dy)) * 0.0947416;
|
||||
outdepth += get_zdepth(ivec2(uv.x - 0.0 * dx, uv.y + 1.0 * dy)) * 0.118318;
|
||||
outdepth += get_zdepth(ivec2(uv.x + 1.0 * dx, uv.y + 1.0 * dy)) * 0.0947416;
|
||||
outdepth += get_zdepth(ivec2(uv.x - 1.0 * dx, uv.y + 0.0 * dy)) * 0.118318;
|
||||
|
||||
outdepth = min(outdepth, texelFetch(strokeDepth, ivec2(uv.x, uv.y), 0).r);
|
||||
outdepth += get_zdepth(ivec2(uv.x, uv.y)) * 0.147761;
|
||||
|
||||
outdepth = min(outdepth, texelFetch(strokeDepth, ivec2(uv.x + 1.0 * dx, uv.y + 0.0 * dy), 0).r);
|
||||
outdepth = min(outdepth, texelFetch(strokeDepth, ivec2(uv.x - 1.0 * dx, uv.y - 1.0 * dy), 0).r);
|
||||
outdepth = min(outdepth, texelFetch(strokeDepth, ivec2(uv.x + 0.0 * dx, uv.y - 1.0 * dy), 0).r);
|
||||
outdepth = min(outdepth, texelFetch(strokeDepth, ivec2(uv.x + 1.0 * dx, uv.y - 1.0 * dy), 0).r);
|
||||
outdepth += get_zdepth(ivec2(uv.x + 1.0 * dx, uv.y + 0.0 * dy)) * 0.118318;
|
||||
outdepth += get_zdepth(ivec2(uv.x - 1.0 * dx, uv.y - 1.0 * dy)) * 0.0947416;
|
||||
outdepth += get_zdepth(ivec2(uv.x + 0.0 * dx, uv.y - 1.0 * dy)) * 0.118318;
|
||||
outdepth += get_zdepth(ivec2(uv.x + 1.0 * dx, uv.y - 1.0 * dy)) * 0.0947416;
|
||||
|
||||
gl_FragDepth = outdepth;
|
||||
|
||||
|
@ -57,6 +73,11 @@ void main()
|
|||
|
||||
FragColor = clamp(outcolor, 0, 1.0);
|
||||
|
||||
if (outcolor.a < 0.02f)
|
||||
/* discar extreme values */
|
||||
if (outcolor.a < 0.02f) {
|
||||
discard;
|
||||
}
|
||||
if ((outdepth <= 0.000001) || (outdepth >= 0.999999)){
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue