GPencil: Change display modes

-Wireframe use Background color for X-Ray off
- Added support to Solid mode.
- Solid mode shows fill or not depending X-Ray.
- Solid can use Single, Material, etc.
- Wireframe and Solid mode don't show FXs.
This commit is contained in:
Antonio Vazquez 2019-03-01 20:50:44 +01:00
parent 589d089472
commit 83c6130e87
5 changed files with 105 additions and 23 deletions

View File

@ -51,6 +51,8 @@
#include "gpencil_engine.h"
#include "UI_resources.h"
/* fill type to communicate to shader */
#define SOLID 0
#define GRADIENT 1
@ -247,8 +249,11 @@ static void DRW_gpencil_recalc_geometry_caches(
static void set_wireframe_color(Object *ob, bGPDlayer *gpl, View3D *v3d,
GPENCIL_StorageList *stl,
MaterialGPencilStyle *gp_style, int id)
MaterialGPencilStyle *gp_style, int id, const bool is_fill)
{
const DRWContextState *draw_ctx = DRW_context_state_get();
World *world = draw_ctx->scene->world;
float color[4];
if (((gp_style->stroke_rgba[3] < GPENCIL_ALPHA_OPACITY_THRESH) ||
(((gp_style->flag & GP_STYLE_STROKE_SHOW) == 0))) &&
@ -263,17 +268,49 @@ static void set_wireframe_color(Object *ob, bGPDlayer *gpl, View3D *v3d,
/* wire color */
if ((v3d) && (id > -1)) {
switch (v3d->shading.wire_color_type) {
const char type = (stl->shgroups[id].shading_type == OB_WIRE) ?
v3d->shading.wire_color_type :
v3d->shading.color_type;
/* if fill and wire, use background color */
if ((is_fill) && (stl->shgroups[id].shading_type == OB_WIRE)) {
if (v3d->shading.background_type == V3D_SHADING_BACKGROUND_THEME) {
UI_GetThemeColor4fv(TH_BACK, stl->shgroups[id].wire_color);
stl->shgroups[id].wire_color[3] = 1.0f;
}
else if (v3d->shading.background_type == V3D_SHADING_BACKGROUND_WORLD) {
color[0] = world->horr;
color[1] = world->horg;
color[2] = world->horb;
color[3] = 1.0f;
linearrgb_to_srgb_v4(stl->shgroups[id].wire_color, color);
}
else {
copy_v3_v3(color, v3d->shading.background_color);
color[3] = 1.0f;
linearrgb_to_srgb_v4(stl->shgroups[id].wire_color, color);
}
return;
}
/* strokes */
switch (type) {
case V3D_SHADING_SINGLE_COLOR:
{
copy_v4_fl(stl->shgroups[id].wire_color, 0.8f);
stl->shgroups[id].wire_color[3] = alpha;
if (stl->shgroups[id].shading_type == OB_WIRE) {
UI_GetThemeColor4fv(TH_WIRE, color);
}
else {
copy_v3_v3(color, v3d->shading.single_color);
}
color[3] = alpha;
linearrgb_to_srgb_v4(stl->shgroups[id].wire_color, color);
break;
}
case V3D_SHADING_OBJECT_COLOR:
{
copy_v4_v4(stl->shgroups[id].wire_color, ob->color);
stl->shgroups[id].wire_color[3] = alpha;
copy_v4_v4(color, ob->color);
color[3] = alpha;
linearrgb_to_srgb_v4(stl->shgroups[id].wire_color, color);
break;
}
case V3D_SHADING_RANDOM_COLOR:
@ -379,11 +416,11 @@ static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
/* shading type */
stl->shgroups[id].shading_type = GPENCIL_USE_SOLID(stl) ? (int)OB_SOLID : shading_type;
stl->shgroups[id].shading_type = GPENCIL_USE_SOLID(stl) ? (int)OB_RENDER : shading_type;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
/* wire color */
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id);
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, true);
DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1);
/* image texture */
@ -479,11 +516,14 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
stl->shgroups[id].caps_mode[1] = gps->caps[1];
DRW_shgroup_uniform_int(grp, "caps_mode", &stl->shgroups[id].caps_mode[0], 2);
stl->shgroups[id].shading_type = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_SOLID : shading_type;
/* viewport x-ray */
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
stl->shgroups[id].shading_type = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_RENDER : shading_type;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
/* wire color */
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id);
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false);
DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1);
}
else {
@ -502,7 +542,10 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
const int zero[2] = { 0, 0 };
DRW_shgroup_uniform_int(grp, "caps_mode", &zero[0], 2);
stl->shgroups[id].shading_type = (int)OB_SOLID;
/* viewport x-ray */
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
stl->shgroups[id].shading_type = (int)OB_RENDER;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
}
@ -586,11 +629,14 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
DRW_shgroup_uniform_int(grp, "mode", &stl->shgroups[id].mode, 1);
DRW_shgroup_uniform_float(grp, "pixfactor", &gpd->pixfactor, 1);
stl->shgroups[id].shading_type = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_SOLID : shading_type;
/* viewport x-ray */
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
stl->shgroups[id].shading_type = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_RENDER : shading_type;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
/* wire color */
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id);
set_wireframe_color(ob, gpl, v3d, stl, gp_style, id, false);
DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1);
}
@ -609,7 +655,10 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
else {
DRW_shgroup_uniform_float(grp, "pixfactor", &stl->storage->pixfactor, 1);
}
stl->shgroups[id].shading_type = (int)OB_SOLID;
/* viewport x-ray */
DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
stl->shgroups[id].shading_type = (int)OB_RENDER;
DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
}
@ -1297,12 +1346,12 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, void *vedata, T
if ((gp_style) && (gp_style->mode == GP_STYLE_MODE_LINE)) {
stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(
e_data, vedata, psl->drawing_pass, e_data->gpencil_stroke_sh, NULL,
gpd, NULL, NULL, gp_style, -1, false, 1.0f, (int)OB_SOLID);
gpd, NULL, NULL, gp_style, -1, false, 1.0f, (int)OB_RENDER);
}
else {
stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_point_create(
e_data, vedata, psl->drawing_pass, e_data->gpencil_point_sh, NULL,
gpd, NULL, gp_style, -1, false, 1.0f, (int)OB_SOLID);
gpd, NULL, gp_style, -1, false, 1.0f, (int)OB_RENDER);
}
/* clean previous version of the batch */

View File

@ -558,7 +558,7 @@ static void gpencil_add_draw_data(void *vedata, Object *ob)
/* FX passses */
cache_ob->has_fx = false;
if ((!stl->storage->simplify_fx) &&
(cache_ob->shading_type != OB_WIRE) &&
(!ELEM(cache_ob->shading_type, OB_WIRE, OB_SOLID)) &&
(BKE_shaderfx_has_gpencil(ob)))
{
cache_ob->has_fx = true;

View File

@ -40,7 +40,8 @@ uniform vec4 wire_color;
#define GP_DRAWMODE_2D 0
#define GP_DRAWMODE_3D 1
#define OB_WIRE 2
#define OB_WIRE 2
#define OB_SOLID 3
in vec4 finalColor;
in vec2 texCoord_interp;
@ -91,7 +92,7 @@ void main()
vec4 chesscolor;
/* wireframe with x-ray discard */
if ((viewport_xray == 1) && (shading_type == OB_WIRE)) {
if ((viewport_xray == 1) && (shading_type == OB_WIRE)) {
discard;
}
@ -165,10 +166,20 @@ void main()
else {
gl_FragDepth = 0.000001;
}
/* if wire mode override colors */
/* if wireframe override colors */
if (shading_type == OB_WIRE) {
fragColor = wire_color;
}
/* solid with x-ray discard */
if (shading_type == OB_SOLID) {
if (viewport_xray == 1) {
/* use 50% of color */
fragColor = vec4(wire_color.rgb, wire_color.a * 0.5);
}
else {
fragColor = wire_color;
}
}
}

View File

@ -5,6 +5,7 @@ uniform float pixsize; /* rv3d->pixsize */
uniform int keep_size;
uniform float objscale;
uniform float pixfactor;
uniform int viewport_xray;
uniform int shading_type;
uniform vec4 wire_color;
@ -19,7 +20,8 @@ out vec2 finaluvdata;
#define TRUE 1
#define OB_WIRE 2
#define OB_WIRE 2
#define OB_SOLID 3
float defaultpixsize = pixsize * (1000.0 / pixfactor);
@ -41,6 +43,15 @@ void main()
finalThickness = 2.0;
finalColor = wire_color;
}
/* for solid override color */
if (shading_type == OB_SOLID) {
if (viewport_xray == 1) {
finalColor = vec4(wire_color.rgb, wire_color.a * 0.5);
}
else {
finalColor = wire_color;
}
}
finaluvdata = uvdata;
}

View File

@ -5,6 +5,7 @@ uniform float pixsize; /* rv3d->pixsize */
uniform int keep_size;
uniform float objscale;
uniform float pixfactor;
uniform int viewport_xray;
uniform int shading_type;
uniform vec4 wire_color;
@ -19,7 +20,8 @@ out vec2 finaluvdata;
#define TRUE 1
#define OB_WIRE 2
#define OB_WIRE 2
#define OB_SOLID 3
float defaultpixsize = pixsize * (1000.0 / pixfactor);
@ -41,6 +43,15 @@ void main(void)
finalThickness = 1.0;
finalColor = wire_color;
}
/* for solid override color */
if (shading_type == OB_SOLID) {
if (viewport_xray == 1) {
finalColor = vec4(wire_color.rgb, wire_color.a * 0.5);
}
else {
finalColor = wire_color;
}
}
finaluvdata = uvdata;
}