[Bf-blender-cvs] [7ba438099b9] greasepencil-object: Improve Blur qualitty when the zoom factor changes
Antonio Vazquez
noreply at git.blender.org
Sat Jul 7 11:04:28 CEST 2018
Commit: 7ba438099b97663f92a2a4acf0ce6cb8fbe24724
Author: Antonio Vazquez
Date: Sat Jul 7 11:04:13 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB7ba438099b97663f92a2a4acf0ce6cb8fbe24724
Improve Blur qualitty when the zoom factor changes
Now the number of pixels to blur depend of the pixel size and not as fix values as before.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index b71c7d42081..a9932242f2b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -145,7 +145,8 @@ static void GPENCIL_dof_nearfar(Object *camera, float coc, float nearfar[2])
* and vertical in different operations.
*/
static void DRW_gpencil_fx_blur(
- ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata)
+ ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data,
+ GPENCIL_Data *vedata, tGPencilObjectCache *cache)
{
if (fx == NULL) {
return;
@@ -160,6 +161,9 @@ static void DRW_gpencil_fx_blur(
RegionView3D *rv3d = draw_ctx->rv3d;
DRWShadingGroup *fx_shgrp;
+ Object *ob = cache->ob;
+ bGPdata *gpd = (bGPdata *)ob->data;
+
fxd->blur[0] = fxd->radius[0];
fxd->blur[1] = fxd->radius[1];
@@ -213,6 +217,12 @@ static void DRW_gpencil_fx_blur(
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_int(fx_shgrp, "blur", &fxd->blur[0], 2);
+
+ DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &ob->loc[0], 1);
+ DRW_shgroup_uniform_float(fx_shgrp, "pixsize", stl->storage->pixsize, 1);
+ DRW_shgroup_uniform_float(fx_shgrp, "pixelsize", &U.pixelsize, 1);
+ DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &gpd->pixfactor, 1);
+
fxd->runtime.fx_sh = fx_shgrp;
}
@@ -403,6 +413,11 @@ static void DRW_gpencil_fx_rim(
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_rim);
DRW_shgroup_uniform_int(fx_shgrp, "blur", &fxd->blur[0], 2);
+ DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &ob->loc[0], 1);
+ DRW_shgroup_uniform_float(fx_shgrp, "pixsize", stl->storage->pixsize, 1);
+ DRW_shgroup_uniform_float(fx_shgrp, "pixelsize", &U.pixelsize, 1);
+ DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &gpd->pixfactor, 1);
+
fxd->runtime.fx_sh_b = fx_shgrp;
/* resolve pass */
@@ -572,7 +587,7 @@ void DRW_gpencil_fx_prepare(
if (effect_is_active(ob, fx, stl->storage->is_render)) {
switch (fx->type) {
case eShaderFxType_Blur:
- DRW_gpencil_fx_blur(fx, ob_idx, e_data, vedata);
+ DRW_gpencil_fx_blur(fx, ob_idx, e_data, vedata, cache);
break;
case eShaderFxType_Colorize:
DRW_gpencil_fx_colorize(fx, e_data, vedata);
diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
index 4ec75c7028f..1d66ba3d4d4 100644
--- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
@@ -1,44 +1,60 @@
-
-out vec4 FragColor;
+uniform mat4 ProjectionMatrix;
+uniform mat4 ViewMatrix;
uniform sampler2D strokeColor;
uniform sampler2D strokeDepth;
uniform int blur[2];
+uniform vec3 loc;
+uniform float pixsize; /* rv3d->pixsize */
+uniform float pixelsize; /* U.pixelsize */
+uniform float pixfactor;
+
+float defaultpixsize = pixsize * pixelsize * (1000.0 / pixfactor);
+vec2 noffset = vec2(blur[0], blur[1]);
+
+out vec4 FragColor;
+
void main()
{
ivec2 uv = ivec2(gl_FragCoord.xy);
+
+ vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0);
+
+ float dx = (ProjectionMatrix[3][3] == 0.0) ? (noffset[0] / (nloc.z * defaultpixsize)) : (noffset[0] / defaultpixsize);
+ 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 */
float outdepth = 0;
- outdepth += texelFetch(strokeDepth, ivec2(uv.x - 1.0 * blur[0], uv.y + 1.0 * blur[1]), 0).r * 0.0947416;
- outdepth += texelFetch(strokeDepth, ivec2(uv.x - 0.0 * blur[0], uv.y + 1.0 * blur[1]), 0).r * 0.118318;
- outdepth += texelFetch(strokeDepth, ivec2(uv.x + 1.0 * blur[0], uv.y + 1.0 * blur[1]), 0).r * 0.0947416;
- outdepth += texelFetch(strokeDepth, ivec2(uv.x - 1.0 * blur[0], uv.y + 0.0 * blur[1]), 0).r * 0.118318;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x - 1.0 * dx, uv.y + 1.0 * dy), 0).r * 0.0947416;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x - 0.0 * dx, uv.y + 1.0 * dy), 0).r * 0.118318;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x + 1.0 * dx, uv.y + 1.0 * dy), 0).r * 0.0947416;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x - 1.0 * dx, uv.y + 0.0 * dy), 0).r * 0.118318;
outdepth += texelFetch(strokeDepth, ivec2(uv.x, uv.y), 0).r * 0.147761;
- outdepth += texelFetch(strokeDepth, ivec2(uv.x + 1.0 * blur[0], uv.y + 0.0 * blur[1]), 0).r * 0.118318;
- outdepth += texelFetch(strokeDepth, ivec2(uv.x - 1.0 * blur[0], uv.y - 1.0 * blur[1]), 0).r * 0.0947416;
- outdepth += texelFetch(strokeDepth, ivec2(uv.x + 0.0 * blur[0], uv.y - 1.0 * blur[1]), 0).r * 0.118318;
- outdepth += texelFetch(strokeDepth, ivec2(uv.x + 1.0 * blur[0], uv.y - 1.0 * blur[1]), 0).r * 0.0947416;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x + 1.0 * dx, uv.y + 0.0 * dy), 0).r * 0.118318;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x - 1.0 * dx, uv.y - 1.0 * dy), 0).r * 0.0947416;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x + 0.0 * dx, uv.y - 1.0 * dy), 0).r * 0.118318;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x + 1.0 * dx, uv.y - 1.0 * dy), 0).r * 0.0947416;
gl_FragDepth = outdepth;
/* color */
vec4 outcolor = vec4(0.0);
- outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * blur[0], uv.y + 1.0 * blur[1]), 0) * 0.0947416;
- outcolor += texelFetch(strokeColor, ivec2(uv.x - 0.0 * blur[0], uv.y + 1.0 * blur[1]), 0) * 0.118318;
- outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * blur[0], uv.y + 1.0 * blur[1]), 0) * 0.0947416;
- outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * blur[0], uv.y + 0.0 * blur[1]), 0) * 0.118318;
+ outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * dx, uv.y + 1.0 * dy), 0) * 0.0947416;
+ outcolor += texelFetch(strokeColor, ivec2(uv.x - 0.0 * dx, uv.y + 1.0 * dy), 0) * 0.118318;
+ outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * dx, uv.y + 1.0 * dy), 0) * 0.0947416;
+ outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * dx, uv.y + 0.0 * dy), 0) * 0.118318;
outcolor += texelFetch(strokeColor, ivec2(uv.x, uv.y), 0) * 0.147761;
- outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * blur[0], uv.y + 0.0 * blur[1]), 0) * 0.118318;
- outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * blur[0], uv.y - 1.0 * blur[1]), 0) * 0.0947416;
- outcolor += texelFetch(strokeColor, ivec2(uv.x + 0.0 * blur[0], uv.y - 1.0 * blur[1]), 0) * 0.118318;
- outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * blur[0], uv.y - 1.0 * blur[1]), 0) * 0.0947416;
+ outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * dx, uv.y + 0.0 * dy), 0) * 0.118318;
+ outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * dx, uv.y - 1.0 * dy), 0) * 0.0947416;
+ outcolor += texelFetch(strokeColor, ivec2(uv.x + 0.0 * dx, uv.y - 1.0 * dy), 0) * 0.118318;
+ outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * dx, uv.y - 1.0 * dy), 0) * 0.0947416;
FragColor = clamp(outcolor, 0, 1.0);
}
More information about the Bf-blender-cvs
mailing list