diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2019-09-06 18:20:54 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2019-09-06 18:23:00 +0300 |
commit | a5a003ed5589657cc53f41ba6042b28a4631cfed (patch) | |
tree | 65e79c4bf58e8a6e76d1d16edc8596ac22056c6b /source/blender/draw/engines | |
parent | 6d8a86c07d5f5c290a9e606a7e03dccac9ddcf43 (diff) |
GPencil: New option to fade not selected objects
Before, it was only possible to fade the active object. The new option allows to fade all non gpencil selected object. This is a common request by artists.
{F7719513}
Reviewers: mendio, pepeland
Reviewed By: mendio
Differential Revision: https://developer.blender.org/D5704
Diffstat (limited to 'source/blender/draw/engines')
4 files changed, 73 insertions, 0 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c index 01c3c10eb9e..e3c3f0b5d12 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c @@ -61,6 +61,38 @@ #define TEXTURE 4 #define PATTERN 5 +/* Verify if must fade object or not. */ +static bool gpencil_fade_object_check(GPENCIL_StorageList *stl, Object *ob) +{ + const DRWContextState *draw_ctx = DRW_context_state_get(); + View3D *v3d = draw_ctx->v3d; + const bool is_overlay = (bool)((v3d) && ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) && + (v3d->gp_flag & V3D_GP_SHOW_PAPER)); + + if ((!is_overlay) || (ob == draw_ctx->obact) || + ((v3d->gp_flag & V3D_GP_FADE_NOACTIVE_GPENCIL) == 0) || + (v3d->overlay.gpencil_paper_opacity == 1.0f)) { + return false; + } + + const bool playing = stl->storage->is_playing; + const bool is_render = (bool)stl->storage->is_render; + const bool is_mat_preview = (bool)stl->storage->is_mat_preview; + const bool is_select = (bool)(DRW_state_is_select() || DRW_state_is_depth()); + + return (bool)((!is_render) && (!playing) && (!is_mat_preview) && (!is_select)); +} + +/* Define Fade object uniforms. */ +static void gpencil_set_fade_uniforms(View3D *v3d, DRWShadingGroup *grp, bool status) +{ + DRW_shgroup_uniform_bool_copy(grp, "fade_on", status); + if (v3d) { + DRW_shgroup_uniform_vec3(grp, "fade_color", v3d->shading.background_color, 1); + DRW_shgroup_uniform_float(grp, "fade_factor", &v3d->overlay.gpencil_paper_opacity, 1); + } +} + /* Get number of vertex for using in GPU VBOs */ static void gpencil_calc_vertex(GPENCIL_StorageList *stl, tGPencilObjectCache *cache_ob, @@ -435,6 +467,9 @@ static DRWShadingGroup *gpencil_shgroup_fill_create(GPENCIL_Data *vedata, DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2); + /* Fade object uniforms. */ + gpencil_set_fade_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob)); + /* wire color */ set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, true); DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1); @@ -557,6 +592,9 @@ DRWShadingGroup *gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, } DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2); + /* Fade object uniforms. */ + gpencil_set_fade_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob)); + /* wire color */ set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false); DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1); @@ -607,6 +645,9 @@ DRWShadingGroup *gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRW_shgroup_uniform_int(grp, "xraymode", &stl->storage->xray, 1); } + /* Fade object uniforms. */ + gpencil_set_fade_uniforms(v3d, grp, false); + /* image texture for pattern */ if ((gp_style) && (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) && (!onion)) { ImBuf *ibuf; @@ -706,6 +747,9 @@ static DRWShadingGroup *gpencil_shgroup_point_create(GPENCIL_Data *vedata, } DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2); + /* Fade object uniforms. */ + gpencil_set_fade_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob)); + /* wire color */ set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false); DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1); @@ -764,6 +808,9 @@ static DRWShadingGroup *gpencil_shgroup_point_create(GPENCIL_Data *vedata, DRW_shgroup_uniform_int(grp, "xraymode", &stl->storage->xray, 1); } + /* Fade object uniforms. */ + gpencil_set_fade_uniforms(v3d, grp, false); + /* image texture */ if ((gp_style) && (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) && (!onion)) { ImBuf *ibuf; diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl index 64bb70f2a3f..7e8f59cf917 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl @@ -26,6 +26,10 @@ uniform int viewport_xray; uniform int shading_type[2]; uniform vec4 wire_color; +uniform bool fade_on; +uniform vec3 fade_color; +uniform float fade_factor; + /* keep this list synchronized with list in gpencil_draw_utils.c */ #define SOLID 0 #define GRADIENT 1 @@ -211,4 +215,8 @@ void main() fragColor.a *= 0.5; } } + /* Apply paper opacity */ + if (fade_on == true) { + fragColor.rgb = mix(fade_color.rgb, fragColor.rgb, fade_factor); + } } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl index 34777018a73..f59c08730fe 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl @@ -14,6 +14,10 @@ in vec4 mColor; in vec2 mTexCoord; out vec4 fragColor; +uniform bool fade_on; +uniform vec3 fade_color; +uniform float fade_factor; + #define texture2D texture #define GPENCIL_MODE_LINE 0 @@ -104,4 +108,9 @@ void main() if (fragColor.a < 0.0035) { discard; } + + /* Apply paper opacity */ + if (fade_on == true) { + fragColor.rgb = mix(fade_color.rgb, fragColor.rgb, fade_factor); + } } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl index 73baacb35d4..e64166527a1 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl @@ -8,6 +8,10 @@ uniform vec4 colormix; uniform float mix_stroke_factor; uniform int shading_type[2]; +uniform bool fade_on; +uniform vec3 fade_color; +uniform float fade_factor; + in vec4 mColor; in vec2 mTexCoord; in vec2 uvfac; @@ -88,4 +92,9 @@ void main() if (fragColor.a < 0.0035) { discard; } + + /* Apply paper opacity */ + if (fade_on == true) { + fragColor.rgb = mix(fade_color.rgb, fragColor.rgb, fade_factor); + } } |