GP: Add support for Wireframe mode

When enable Wireframe mode in the shading type, all strokes are displayed as simple 1 pixel lines.

The color of the line is equal to the stroke color or the fill color if the fill is enabled and the stroke is disabled or has invisible alpha value.

In wireframe mode, all FX are disabled because sometimes the effects can make the lines invisible.

The modifiers are not disabled.

Still pending to decide if we must add support for Random colors, but not sure if this is useful in 2D.
This commit is contained in:
Antonio Vazquez 2019-02-25 17:41:02 +01:00
parent cfc2fa33bf
commit 5d8a8a6842
4 changed files with 45 additions and 9 deletions

View File

@ -598,7 +598,7 @@ static void gpencil_add_stroke_vertexdata(
GpencilBatchCache *cache,
Object *ob, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps,
const float opacity, const float tintcolor[4], const bool onion,
const bool custonion)
const bool custonion, const bool use_wiremode)
{
float tcolor[4];
float ink[4];
@ -616,6 +616,15 @@ static void gpencil_add_stroke_vertexdata(
else {
interp_v3_v3v3(tcolor, gps->runtime.tmp_stroke_rgba, tintcolor, tintcolor[3]);
tcolor[3] = gps->runtime.tmp_stroke_rgba[3] * opacity;
if ((use_wiremode) &&
((gps->runtime.tmp_stroke_rgba[3] < GPENCIL_ALPHA_OPACITY_THRESH) ||
(((gp_style->flag & GP_STYLE_STROKE_SHOW) == 0))) &&
(gps->runtime.tmp_fill_rgba[3] >= GPENCIL_ALPHA_OPACITY_THRESH))
{
interp_v3_v3v3(tcolor, gps->runtime.tmp_fill_rgba, tintcolor, tintcolor[3]);
tcolor[3] = gps->runtime.tmp_fill_rgba[3] * opacity;
}
}
copy_v4_v4(ink, tcolor);
}
@ -629,8 +638,14 @@ static void gpencil_add_stroke_vertexdata(
}
}
sthickness = gps->thickness + gpl->line_change;
CLAMP_MIN(sthickness, 1);
/* if wireframe mode, set thickeness to 1 */
if (!use_wiremode) {
sthickness = gps->thickness + gpl->line_change;
CLAMP_MIN(sthickness, 1);
}
else {
sthickness = 1;
}
if ((gps->totpoints > 1) && (gp_style->mode == GP_STYLE_MODE_LINE)) {
/* create vertex data */
@ -812,6 +827,7 @@ static void gpencil_draw_strokes(
/* fill */
if ((gp_style->flag & GP_STYLE_FILL_SHOW) &&
(!stl->storage->simplify_fill) &&
(stl->storage->shading_type != OB_WIRE) &&
((gps->flag & GP_STROKE_NOFILL) == 0))
{
gpencil_add_fill_vertexdata(
@ -821,13 +837,15 @@ static void gpencil_draw_strokes(
/* stroke */
/* No fill strokes, must show stroke always */
if (((gp_style->flag & GP_STYLE_STROKE_SHOW) ||
(gps->flag & GP_STROKE_NOFILL)) &&
(gps->flag & GP_STROKE_NOFILL) ||
(stl->storage->shading_type == OB_WIRE)) &&
((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);
opacity, tintcolor, false, custonion,
(stl->storage->shading_type == OB_WIRE));
}
}
}
@ -906,7 +924,9 @@ static void gpencil_draw_onion_strokes(
/* stroke */
gpencil_add_stroke_vertexdata(
cache, ob, gpl, gpf, gps, opacity, tintcolor, true, custonion);
cache, ob, gpl, gpf, gps, opacity, tintcolor,
true, custonion,
(stl->storage->shading_type == OB_WIRE));
stl->storage->shgroup_id++;
}

View File

@ -385,6 +385,14 @@ void GPENCIL_cache_init(void *vedata)
stl->storage->simplify_fx = GP_SIMPLIFY_FX(scene, stl->storage->is_playing);
stl->storage->simplify_blend = GP_SIMPLIFY_BLEND(scene, stl->storage->is_playing);
/* save shading type */
if (v3d) {
stl->storage->shading_type = v3d->shading.type;
}
else {
stl->storage->shading_type = OB_SOLID;
}
/* save pixsize */
stl->storage->pixsize = DRW_viewport_pixelsize_get();
if ((!DRW_state_is_opengl_render()) && (stl->storage->is_render)) {
@ -514,7 +522,9 @@ void GPENCIL_cache_init(void *vedata)
DRW_shgroup_uniform_int(mix_shgrp, "tonemapping", &stl->storage->tonemapping, 1);
/* create effects passes */
if (!stl->storage->simplify_fx) {
if ((!stl->storage->simplify_fx) &&
(stl->storage->shading_type != OB_WIRE))
{
GPENCIL_create_fx_passes(psl);
}
}
@ -542,7 +552,8 @@ static void gpencil_add_draw_data(void *vedata, Object *ob)
/* FX passses */
cache_ob->has_fx = false;
if ((!stl->storage->simplify_fx) &&
(BKE_shaderfx_has_gpencil(ob)))
(stl->storage->shading_type != OB_WIRE) &&
(BKE_shaderfx_has_gpencil(ob)))
{
cache_ob->has_fx = true;
if ((!stl->storage->simplify_fx) && (!is_multiedit)) {

View File

@ -158,6 +158,9 @@ typedef struct GPENCIL_Storage {
float grid_matrix[4][4];
/* shading type */
char shading_type;
Object *camera; /* camera pointer for render mode */
} GPENCIL_Storage;

View File

@ -746,9 +746,11 @@ void DRW_gpencil_fx_prepare(
tGPencilObjectCache *cache)
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
const bool wiremode = (bool)(stl->storage->shading_type == OB_WIRE);
int ob_idx = cache->idx;
if (cache->shader_fx.first == NULL) {
if ((wiremode) || (cache->shader_fx.first == NULL)) {
return;
}
/* loop FX */