Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/draw/engines/gpencil/gpencil_draw_utils.c')
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_draw_utils.c94
1 files changed, 69 insertions, 25 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index e3c3f0b5d12..3d1aad827c5 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -83,13 +83,49 @@ static bool gpencil_fade_object_check(GPENCIL_StorageList *stl, Object *ob)
return (bool)((!is_render) && (!playing) && (!is_mat_preview) && (!is_select));
}
+/* Define Fade layer uniforms. */
+static void gpencil_set_fade_layer_uniforms(
+ GPENCIL_StorageList *stl, DRWShadingGroup *grp, Object *ob, bGPDlayer *gpl, const bool skip)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+ const bool overlay = v3d != NULL ? (bool)((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) : true;
+ const bool is_fade = (v3d) && (v3d->gp_flag & V3D_GP_FADE_NOACTIVE_LAYERS) &&
+ (draw_ctx->obact) && (draw_ctx->obact == ob) &&
+ ((gpl->flag & GP_LAYER_ACTIVE) == 0);
+
+ 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());
+
+ /* If drawing or not fading layer, skip. */
+ if ((!overlay) || (skip) || (!is_fade) || (is_render) || (playing) || (is_mat_preview) ||
+ (is_select)) {
+ DRW_shgroup_uniform_int_copy(grp, "fade_layer", 0);
+ return;
+ }
+
+ /* If layer is above active, use alpha (2) if below use mix with background (1). */
+ if (stl->storage->is_ontop) {
+ DRW_shgroup_uniform_int_copy(grp, "fade_layer", 2);
+ }
+ else {
+ DRW_shgroup_uniform_int_copy(grp, "fade_layer", 1);
+ }
+ if (v3d) {
+ DRW_shgroup_uniform_vec3(grp, "fade_color", v3d->shading.background_color, 1);
+ DRW_shgroup_uniform_float(grp, "fade_layer_factor", &v3d->overlay.gpencil_fade_layer, 1);
+ }
+}
+
/* Define Fade object uniforms. */
-static void gpencil_set_fade_uniforms(View3D *v3d, DRWShadingGroup *grp, bool status)
+static void gpencil_set_fade_ob_uniforms(View3D *v3d, DRWShadingGroup *grp, bool status)
{
- DRW_shgroup_uniform_bool_copy(grp, "fade_on", status);
+ DRW_shgroup_uniform_bool_copy(grp, "fade_ob", 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);
+ DRW_shgroup_uniform_float(grp, "fade_ob_factor", &v3d->overlay.gpencil_paper_opacity, 1);
}
}
@@ -286,10 +322,6 @@ static void set_wireframe_color(Object *ob,
{
const DRWContextState *draw_ctx = DRW_context_state_get();
World *world = draw_ctx->scene->world;
- const bool is_fade = (v3d) && (v3d->gp_flag & V3D_GP_FADE_NOACTIVE_LAYERS) &&
- (draw_ctx->obact) && (draw_ctx->obact == ob) &&
- ((gpl->flag & GP_LAYER_ACTIVE) == 0);
- const float opacity = is_fade ? v3d->overlay.gpencil_fade_layer : 1.0f;
float color[4];
if (((gp_style->stroke_rgba[3] < GPENCIL_ALPHA_OPACITY_THRESH) ||
@@ -300,7 +332,6 @@ static void set_wireframe_color(Object *ob,
else {
copy_v4_v4(color, gp_style->stroke_rgba);
}
- float alpha = color[3] * opacity;
/* wire color */
if ((v3d) && (id > -1)) {
@@ -337,13 +368,13 @@ static void set_wireframe_color(Object *ob,
else {
copy_v3_v3(color, v3d->shading.single_color);
}
- color[3] = is_fade ? alpha : 1.0f;
+ color[3] = 1.0f;
linearrgb_to_srgb_v4(stl->shgroups[id].wire_color, color);
break;
}
case V3D_SHADING_OBJECT_COLOR: {
copy_v4_v4(color, ob->color);
- color[3] = is_fade ? alpha : 1.0f;
+ color[3] = 1.0f;
linearrgb_to_srgb_v4(stl->shgroups[id].wire_color, color);
break;
}
@@ -360,7 +391,7 @@ static void set_wireframe_color(Object *ob,
hsv_to_rgb_v(hsv, &wire_col[0]);
copy_v3_v3(stl->shgroups[id].wire_color, wire_col);
- stl->shgroups[id].wire_color[3] = is_fade ? alpha : 1.0f;
+ stl->shgroups[id].wire_color[3] = 1.0f;
break;
}
default: {
@@ -375,7 +406,7 @@ static void set_wireframe_color(Object *ob,
/* if solid, the alpha must be set to alpha */
if (stl->shgroups[id].shading_type[0] == OB_SOLID) {
- stl->shgroups[id].wire_color[3] = is_fade ? alpha : 1.0f;
+ stl->shgroups[id].wire_color[3] = 1.0f;
}
}
@@ -467,8 +498,11 @@ static DRWShadingGroup *gpencil_shgroup_fill_create(GPENCIL_Data *vedata,
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
+ /* Fade layer uniforms. */
+ gpencil_set_fade_layer_uniforms(stl, grp, ob, gpl, false);
+
/* Fade object uniforms. */
- gpencil_set_fade_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob));
+ gpencil_set_fade_ob_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob));
/* wire color */
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, true);
@@ -592,8 +626,11 @@ DRWShadingGroup *gpencil_shgroup_stroke_create(GPENCIL_Data *vedata,
}
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
+ /* Fade layer uniforms. */
+ gpencil_set_fade_layer_uniforms(stl, grp, ob, gpl, false);
+
/* Fade object uniforms. */
- gpencil_set_fade_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob));
+ gpencil_set_fade_ob_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob));
/* wire color */
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false);
@@ -645,8 +682,11 @@ DRWShadingGroup *gpencil_shgroup_stroke_create(GPENCIL_Data *vedata,
DRW_shgroup_uniform_int(grp, "xraymode", &stl->storage->xray, 1);
}
+ /* Fade layer uniforms. */
+ gpencil_set_fade_layer_uniforms(stl, grp, ob, gpl, true);
+
/* Fade object uniforms. */
- gpencil_set_fade_uniforms(v3d, grp, false);
+ gpencil_set_fade_ob_uniforms(v3d, grp, false);
/* image texture for pattern */
if ((gp_style) && (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) && (!onion)) {
@@ -747,8 +787,11 @@ static DRWShadingGroup *gpencil_shgroup_point_create(GPENCIL_Data *vedata,
}
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type[0], 2);
+ /* Fade layer uniforms. */
+ gpencil_set_fade_layer_uniforms(stl, grp, ob, gpl, false);
+
/* Fade object uniforms. */
- gpencil_set_fade_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob));
+ gpencil_set_fade_ob_uniforms(v3d, grp, gpencil_fade_object_check(stl, ob));
/* wire color */
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false);
@@ -808,8 +851,11 @@ static DRWShadingGroup *gpencil_shgroup_point_create(GPENCIL_Data *vedata,
DRW_shgroup_uniform_int(grp, "xraymode", &stl->storage->xray, 1);
}
+ /* Fade layer uniforms. */
+ gpencil_set_fade_layer_uniforms(stl, grp, ob, gpl, true);
+
/* Fade object uniforms. */
- gpencil_set_fade_uniforms(v3d, grp, false);
+ gpencil_set_fade_ob_uniforms(v3d, grp, false);
/* image texture */
if ((gp_style) && (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) && (!onion)) {
@@ -1684,6 +1730,8 @@ static void gpencil_shgroups_create(GPENCIL_e_data *e_data,
int start_edlin = 0;
uint stencil_id = 1;
+ /* Flag to determine if the layer is above active layer. */
+ stl->storage->is_ontop = false;
for (int i = 0; i < cache->grp_used; i++) {
elm = &cache->grp_cache[i];
array_elm = &cache_ob->shgrp_array[idx];
@@ -1711,6 +1759,10 @@ static void gpencil_shgroups_create(GPENCIL_e_data *e_data,
}
gpl = elm->gpl;
+ if ((!stl->storage->is_ontop) && (gpl->flag & GP_LAYER_ACTIVE)) {
+ stl->storage->is_ontop = true;
+ }
+
bGPDframe *gpf = elm->gpf;
bGPDstroke *gps = elm->gps;
MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
@@ -1956,12 +2008,10 @@ void gpencil_populate_datablock(GPENCIL_e_data *e_data,
int cfra_eval = (int)DEG_get_ctime(draw_ctx->depsgraph);
bGPDframe *gpf_eval = NULL;
- const bool overlay = v3d != NULL ? (bool)((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) : true;
const bool time_remap = BKE_gpencil_has_time_modifiers(ob);
float opacity;
bGPDframe *gpf = NULL;
- bGPDlayer *gpl_active = BKE_gpencil_layer_getactive(gpd);
/* check if playing animation */
const bool playing = stl->storage->is_playing;
@@ -2017,12 +2067,6 @@ void gpencil_populate_datablock(GPENCIL_e_data *e_data,
(v3d->overlay.flag & V3D_OVERLAY_BONE_SELECT)) {
opacity = opacity * v3d->overlay.xray_alpha_bone;
}
- /* fade no active layers */
- if ((overlay) && (draw_ctx->object_mode == OB_MODE_PAINT_GPENCIL) &&
- (v3d->gp_flag & V3D_GP_FADE_NOACTIVE_LAYERS) && (draw_ctx->obact) &&
- (draw_ctx->obact == ob) && (gpl != gpl_active)) {
- opacity = opacity * v3d->overlay.gpencil_fade_layer;
- }
/* Get evaluated frames array data */
int idx_eval = BLI_findindex(&gpd->layers, gpl);