Commit: 18c43863f464f231a74454bec45c388abc737304
Author: Antonioya
Date:   Thu Feb 28 10:47:57 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB18c43863f464f231a74454bec45c388abc737304

GPencil: Draw Outline to Active and Selected objects

Now an outline is drawn when the grease pencil is selected.

===================================================================

M       source/blender/draw/engines/gpencil/gpencil_engine.c
M       source/blender/draw/engines/gpencil/gpencil_engine.h
M       source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl

===================================================================

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index a045792ad4d..2ce7a53e968 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -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) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h 
b/source/blender/draw/engines/gpencil/gpencil_engine.h
index ed4915651f1..6f42170131e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -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 */
diff --git 
a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl 
b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
index eb64947999e..4497828fbd5 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
@@ -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;
+                       }
+               }
+       }
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to