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:
authorAntonioya <blendergit@gmail.com>2018-11-26 20:12:39 +0300
committerAntonioya <blendergit@gmail.com>2018-11-26 20:12:39 +0300
commit99f7934e19ddf6796e866d2ddc0c3882ed8fcc2b (patch)
tree45e39dc690fd17f989bceac35e8ecf794417af34 /source/blender/draw/engines/gpencil/gpencil_draw_utils.c
parentc0816cd03b42399e75a285d5e5dd1319e5054f17 (diff)
GP: New Blend Layers functionality
Now it's possible define the blend mode between layers including the option to clamp the layer using underlying layers. Also a new Simplify option has been added to disable blend layers.
Diffstat (limited to 'source/blender/draw/engines/gpencil/gpencil_draw_utils.c')
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_draw_utils.c125
1 files changed, 87 insertions, 38 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index c8b70953f87..e4d6fa582b8 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -244,13 +244,15 @@ static void gpencil_stroke_2d_flat(const bGPDspoint *points, int totpoints, floa
}
/* recalc the internal geometry caches for fill and uvs */
-static void DRW_gpencil_recalc_geometry_caches(Object *ob, MaterialGPencilStyle *gp_style, bGPDstroke *gps)
+static void DRW_gpencil_recalc_geometry_caches(
+ Object *ob, bGPDlayer *gpl, MaterialGPencilStyle *gp_style, bGPDstroke *gps)
{
if (gps->flag & GP_STROKE_RECALC_CACHES) {
/* Calculate triangles cache for filling area (must be done only after changes) */
if ((gps->tot_triangles == 0) || (gps->triangles == NULL)) {
if ((gps->totpoints > 2) &&
- ((gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gp_style->fill_style > 0)))
+ ((gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) ||
+ (gp_style->fill_style > 0) || (gpl->blend_mode != eGplBlendMode_Normal)))
{
DRW_gpencil_triangulate_stroke_fill(ob, gps);
}
@@ -559,7 +561,9 @@ static void gpencil_add_fill_vertexdata(
/* set color using material, tint color and opacity */
interp_v3_v3v3(tfill, gps->runtime.tmp_fill_rgba, tintcolor, tintcolor[3]);
tfill[3] = gps->runtime.tmp_fill_rgba[3] * opacity;
- if ((tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gp_style->fill_style > 0)) {
+ if ((tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) ||
+ (gp_style->fill_style > 0) ||
+ (gpl->blend_mode != eGplBlendMode_Normal)) {
if (cache->is_dirty) {
const float *color;
if (!onion) {
@@ -581,7 +585,8 @@ static void gpencil_add_fill_vertexdata(
/* add to list of groups */
if (old_len < cache->b_fill.vbo_len) {
cache->grp_cache = gpencil_group_cache_add(
- cache->grp_cache, gpl, gpf, gps, eGpencilBatchGroupType_Fill, onion,
+ cache->grp_cache, gpl, gpf, gps,
+ eGpencilBatchGroupType_Fill, onion,
cache->b_fill.vbo_len,
&cache->grp_size, &cache->grp_used);
}
@@ -637,7 +642,8 @@ static void gpencil_add_stroke_vertexdata(
/* add to list of groups */
if (old_len < cache->b_stroke.vbo_len) {
cache->grp_cache = gpencil_group_cache_add(
- cache->grp_cache, gpl, gpf, gps, eGpencilBatchGroupType_Stroke, onion,
+ cache->grp_cache, gpl, gpf, gps,
+ eGpencilBatchGroupType_Stroke, onion,
cache->b_stroke.vbo_len,
&cache->grp_size, &cache->grp_used);
}
@@ -687,7 +693,8 @@ static void gpencil_add_editpoints_vertexdata(
/* add to list of groups */
cache->grp_cache = gpencil_group_cache_add(
- cache->grp_cache, gpl, gpf, gps, eGpencilBatchGroupType_Edlin, false,
+ cache->grp_cache, gpl, gpf, gps,
+ eGpencilBatchGroupType_Edlin, false,
cache->b_edlin.vbo_len,
&cache->grp_size, &cache->grp_used);
}
@@ -699,7 +706,8 @@ static void gpencil_add_editpoints_vertexdata(
/* add to list of groups */
cache->grp_cache = gpencil_group_cache_add(
- cache->grp_cache, gpl, gpf, gps, eGpencilBatchGroupType_Edit, false,
+ cache->grp_cache, gpl, gpf, gps,
+ eGpencilBatchGroupType_Edit, false,
cache->b_edit.vbo_len,
&cache->grp_size, &cache->grp_used);
}
@@ -771,13 +779,14 @@ static void gpencil_draw_strokes(
/* be sure recalc all cache in source stroke to avoid recalculation when frame change
* and improve fps */
if (src_gps) {
- DRW_gpencil_recalc_geometry_caches(ob, gp_style, src_gps);
+ DRW_gpencil_recalc_geometry_caches(ob, gpl, gp_style, src_gps);
}
/* if the fill has any value, it's considered a fill and is not drawn if simplify fill is enabled */
if ((stl->storage->simplify_fill) && (scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_REMOVE_FILL_LINE)) {
if ((gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) ||
- (gp_style->fill_style > GP_STYLE_FILL_STYLE_SOLID))
+ (gp_style->fill_style > GP_STYLE_FILL_STYLE_SOLID) ||
+ (gpl->blend_mode != eGplBlendMode_Normal))
{
GP_SET_SRC_GPS(src_gps);
continue;
@@ -798,21 +807,28 @@ static void gpencil_draw_strokes(
}
}
- /* fill */
- if ((gp_style->flag & GP_STYLE_FILL_SHOW) &&
- (!stl->storage->simplify_fill))
+ /* hide any blend layer */
+ if ((!stl->storage->simplify_blend) ||
+ (gpl->blend_mode == eGplBlendMode_Normal))
{
- gpencil_add_fill_vertexdata(
- cache, ob, gpl, derived_gpf, gps,
- opacity, tintcolor, false, custonion);
- }
- /* stroke */
- if ((gp_style->flag & GP_STYLE_STROKE_SHOW) &&
- (gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH))
- {
- gpencil_add_stroke_vertexdata(
- cache, ob, gpl, derived_gpf, gps,
- opacity, tintcolor, false, custonion);
+ /* fill */
+ if ((gp_style->flag & GP_STYLE_FILL_SHOW) &&
+ (!stl->storage->simplify_fill) &&
+ ((gps->flag & GP_STROKE_NOFILL) == 0))
+ {
+ gpencil_add_fill_vertexdata(
+ cache, ob, gpl, derived_gpf, gps,
+ opacity, tintcolor, false, custonion);
+ }
+ /* stroke */
+ if ((gp_style->flag & GP_STYLE_STROKE_SHOW) &&
+ ((gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) ||
+ (gpl->blend_mode == eGplBlendMode_Normal)))
+ {
+ gpencil_add_stroke_vertexdata(
+ cache, ob, gpl, derived_gpf, gps,
+ opacity, tintcolor, false, custonion);
+ }
}
}
@@ -1253,12 +1269,21 @@ static void DRW_gpencil_create_batches(GpencilBatchCache *cache)
/* create all shading groups */
static void DRW_gpencil_shgroups_create(
GPENCIL_e_data *e_data, void *vedata,
- Object *ob, bGPdata *gpd,
+ Object *ob,
GpencilBatchCache *cache, tGPencilObjectCache *cache_ob)
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+ bGPdata *gpd = (bGPdata *)ob->data;
+
+ GpencilBatchGroup *elm = NULL;
DRWShadingGroup *shgrp = NULL;
+ tGPencilObjectCache_shgrp *array_elm = NULL;
+
+ bGPDlayer *gpl = NULL;
+ bGPDlayer *gpl_prev = NULL;
+ int idx = 0;
+ bool tag_first = false;
int start_stroke = 0;
int start_point = 0;
@@ -1266,12 +1291,28 @@ static void DRW_gpencil_shgroups_create(
int start_edit = 0;
int start_edlin = 0;
- cache_ob->init_grp = NULL;
- cache_ob->end_grp = NULL;
-
for (int i = 0; i < cache->grp_used; i++) {
- GpencilBatchGroup *elm = &cache->grp_cache[i];
- bGPDlayer *gpl = elm->gpl;
+ elm = &cache->grp_cache[i];
+ array_elm = &cache_ob->shgrp_array[idx];
+
+ /* save last group when change */
+ if (gpl_prev == NULL) {
+ gpl_prev = elm->gpl;
+ tag_first = true;
+ }
+ else {
+ if (elm->gpl != gpl_prev)
+ {
+ /* first layer is always blend Normal */
+ array_elm->mode = idx == 0 ? eGplBlendMode_Normal: gpl->blend_mode;
+ array_elm->end_shgrp = shgrp;
+ gpl_prev = elm->gpl;
+ tag_first = true;
+ idx++;
+ }
+ }
+
+ gpl = elm->gpl;
bGPDframe *gpf = elm->gpf;
bGPDstroke *gps = elm->gps;
MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
@@ -1365,14 +1406,22 @@ static void DRW_gpencil_shgroups_create(
}
}
/* save first group */
- if ((shgrp != NULL) && (cache_ob->init_grp == NULL)) {
- cache_ob->init_grp = shgrp;
+ if ((shgrp != NULL) && (tag_first)) {
+ array_elm = &cache_ob->shgrp_array[idx];
+ array_elm->mode = idx == 0 ? eGplBlendMode_Normal: gpl->blend_mode;
+ array_elm->clamp_layer = gpl->flag & GP_LAYER_USE_MASK;
+ array_elm->blend_opacity = gpl->opacity;
+ array_elm->init_shgrp = shgrp;
+ cache_ob->tot_layers++;
+
+ tag_first = false;
}
}
/* save last group */
if (shgrp != NULL) {
- cache_ob->end_grp = shgrp;
+ array_elm->mode = idx == 0 ? eGplBlendMode_Normal : gpl->blend_mode;
+ array_elm->end_shgrp = shgrp;
}
}
/* populate a datablock for multiedit (no onions, no modifiers) */
@@ -1425,7 +1474,7 @@ void DRW_gpencil_populate_multiedit(
/* create batchs and shading groups */
DRW_gpencil_create_batches(cache);
- DRW_gpencil_shgroups_create(e_data, vedata, ob, gpd, cache, cache_ob);
+ DRW_gpencil_shgroups_create(e_data, vedata, ob, cache, cache_ob);
cache->is_dirty = false;
}
@@ -1465,7 +1514,7 @@ void DRW_gpencil_populate_datablock(
/* if object is duplicate, only create shading groups */
if (cache_ob->is_dup_ob) {
- DRW_gpencil_shgroups_create(e_data, vedata, ob, gpd, cache, cache_ob);
+ DRW_gpencil_shgroups_create(e_data, vedata, ob, cache, cache_ob);
return;
}
@@ -1481,8 +1530,9 @@ void DRW_gpencil_populate_datablock(
/* draw normal strokes */
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
/* don't draw layer if hidden */
- if (gpl->flag & GP_LAYER_HIDE)
+ if (gpl->flag & GP_LAYER_HIDE) {
continue;
+ }
/* filter view layer to gp layers in the same view layer (for compo) */
if ((stl->storage->is_render) && (gpl->viewlayername[0] != '\0')) {
@@ -1560,7 +1610,7 @@ void DRW_gpencil_populate_datablock(
/* create batchs and shading groups */
DRW_gpencil_create_batches(cache);
- DRW_gpencil_shgroups_create(e_data, vedata, ob, gpd, cache, cache_ob);
+ DRW_gpencil_shgroups_create(e_data, vedata, ob, cache, cache_ob);
cache->is_dirty = false;
}
@@ -1574,9 +1624,8 @@ void DRW_gpencil_populate_particles(GPENCIL_e_data *e_data, void *vedata)
tGPencilObjectCache *cache_ob = &stl->g_data->gp_object_cache[i];
Object *ob = cache_ob->ob;
if (cache_ob->is_dup_ob) {
- bGPdata *gpd = (bGPdata *)ob->data;
GpencilBatchCache *cache = ob->runtime.gpencil_cache;
- DRW_gpencil_shgroups_create(e_data, vedata, ob, gpd, cache, cache_ob);
+ DRW_gpencil_shgroups_create(e_data, vedata, ob, cache, cache_ob);
}
}
}