GPencil: Draw Outline to Active and Selected objects

Now an outline is drawn when the grease pencil is selected.
This commit is contained in:
Antonio Vazquez 2019-02-28 10:47:57 +01:00
parent 9ddc2064a4
commit 5411efdeed
3 changed files with 50 additions and 0 deletions

View File

@ -40,6 +40,8 @@
#include "ED_view3d.h"
#include "ED_screen.h"
#include "UI_resources.h"
extern char datatoc_gpencil_fill_vert_glsl[];
extern char datatoc_gpencil_fill_frag_glsl[];
@ -455,6 +457,8 @@ void GPENCIL_cache_init(void *vedata)
DRW_shgroup_uniform_texture_ref(mix_shgrp, "strokeColor", &e_data.input_color_tx);
DRW_shgroup_uniform_texture_ref(mix_shgrp, "strokeDepth", &e_data.input_depth_tx);
DRW_shgroup_uniform_int(mix_shgrp, "tonemapping", &stl->storage->tonemapping, 1);
DRW_shgroup_uniform_int(mix_shgrp, "do_select", &stl->storage->do_select, 1);
DRW_shgroup_uniform_vec4(mix_shgrp, "select_color", stl->storage->select_color, 1);
/* mix pass no blend used to copy between passes. A separated pass is required
* because if mix_pass is used, the acumulation of blend degrade the colors.
@ -470,6 +474,8 @@ void GPENCIL_cache_init(void *vedata)
DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeColor", &e_data.input_color_tx);
DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeDepth", &e_data.input_depth_tx);
DRW_shgroup_uniform_int(mix_shgrp_noblend, "tonemapping", &stl->storage->tonemapping, 1);
DRW_shgroup_uniform_int(mix_shgrp_noblend, "do_select", &stl->storage->do_select, 1);
DRW_shgroup_uniform_vec4(mix_shgrp_noblend, "select_color", stl->storage->select_color, 1);
/* Painting session pass (used only to speedup while the user is drawing )
* This pass is used to show the snapshot of the current grease pencil strokes captured
@ -881,6 +887,7 @@ void GPENCIL_draw_scene(void *ved)
for (int i = 0; i < stl->g_data->gp_cache_used; i++) {
cache_ob = &stl->g_data->gp_object_cache[i];
Object *ob = cache_ob->ob;
bGPdata *gpd = cache_ob->gpd;
init_shgrp = NULL;
/* Render stroke in separated framebuffer */
@ -976,8 +983,24 @@ void GPENCIL_draw_scene(void *ved)
/* tonemapping */
stl->storage->tonemapping = stl->storage->is_render ? 1 : 0;
/* active select flag and selection color */
stl->storage->do_select = ((ob->base_flag & BASE_SELECTED) &&
(ob->mode == OB_MODE_OBJECT) &&
(!is_render));
/* if active object is not object mode, disable for all objects */
if ((draw_ctx->obact) && (draw_ctx->obact->mode != OB_MODE_OBJECT)) {
stl->storage->do_select = 0;
}
UI_GetThemeColor4fv((ob == draw_ctx->obact) ? TH_ACTIVE : TH_SELECT,
stl->storage->select_color);
/* draw mix pass */
DRW_draw_pass(psl->mix_pass);
/* disable select flag */
stl->storage->do_select = 0;
/* prepare for fast drawing */
if (!is_render) {
if (!playing) {

View File

@ -146,6 +146,8 @@ typedef struct GPENCIL_Storage {
const float *pixsize;
float render_pixsize;
int tonemapping;
int do_select;
float select_color[4];
short multisamples;
short framebuffer_flag; /* flag what framebuffer need to create */

View File

@ -5,6 +5,8 @@ out vec4 FragColor;
uniform sampler2D strokeColor;
uniform sampler2D strokeDepth;
uniform int tonemapping;
uniform vec4 select_color;
uniform int do_select;
float srgb_to_linearrgb(float c)
{
@ -26,6 +28,20 @@ float linearrgb_to_srgb(float c)
}
}
bool check_borders(ivec2 uv, int size)
{
for (int x = -size; x <= size; x++) {
for (int y = -size; y <= size; y++) {
vec4 stroke_color = texelFetch(strokeColor, ivec2(uv.x + x, uv.y + y), 0).rgba;
if (stroke_color.a > 0) {
return true;
}
}
}
return false;
}
void main()
{
ivec2 uv = ivec2(gl_FragCoord.xy);
@ -46,4 +62,13 @@ void main()
FragColor = clamp(stroke_color, 0.0, 1.0);
gl_FragDepth = clamp(stroke_depth, 0.0, 1.0);
if (do_select == 1) {
if (stroke_color.a == 0) {
if (check_borders(uv, 1)) {
FragColor = select_color;
gl_FragDepth = 0.000001;
}
}
}
}