diff options
author | Antonioya <blendergit@gmail.com> | 2019-04-18 15:19:00 +0300 |
---|---|---|
committer | Antonioya <blendergit@gmail.com> | 2019-04-18 20:33:06 +0300 |
commit | 4dce18fb51f17269161d1c2a16571502b97a860b (patch) | |
tree | 1479ee2f358ff688c4b4da79832da566930fdfca /source/blender/draw | |
parent | 4439e5d0ba3ffde3841ec44405a9bcaf800be279 (diff) |
GPencil: Add option to mix color with texture
This was already supported in Fill, but not in Strokes. This adds more artistic options when use textured strokes.
Diffstat (limited to 'source/blender/draw')
4 files changed, 65 insertions, 13 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c index 320b621f903..5dda2faff42 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c @@ -421,7 +421,7 @@ static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(GPENCIL_e_data *e_data, DRW_shgroup_uniform_float(grp, "texture_opacity", &gp_style->texture_opacity, 1); DRW_shgroup_uniform_float(grp, "layer_opacity", &gpl->opacity, 1); - stl->shgroups[id].texture_mix = gp_style->flag & GP_STYLE_COLOR_TEX_MIX ? 1 : 0; + stl->shgroups[id].texture_mix = gp_style->flag & GP_STYLE_FILL_TEX_MIX ? 1 : 0; DRW_shgroup_uniform_int(grp, "texture_mix", &stl->shgroups[id].texture_mix, 1); stl->shgroups[id].texture_flip = gp_style->flag & GP_STYLE_COLOR_FLIP_FILL ? 1 : 0; @@ -450,7 +450,7 @@ static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(GPENCIL_e_data *e_data, DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1); /* image texture */ - if ((gp_style->flag & GP_STYLE_COLOR_TEX_MIX) || + if ((gp_style->flag & GP_STYLE_FILL_TEX_MIX) || (gp_style->fill_style & GP_STYLE_FILL_STYLE_TEXTURE)) { ImBuf *ibuf; Image *image = gp_style->ima; @@ -569,6 +569,12 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_e_data *e_data, /* 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); + + /* mix stroke factor */ + stl->shgroups[id].mix_stroke_factor = (gp_style->flag & GP_STYLE_STROKE_TEX_MIX) ? + gp_style->mix_stroke_factor : + 0.0f; + DRW_shgroup_uniform_float(grp, "mix_stroke_factor", &stl->shgroups[id].mix_stroke_factor, 1); } else { stl->storage->obj_scale = 1.0f; @@ -591,8 +597,16 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_e_data *e_data, /* viewport x-ray */ DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1); DRW_shgroup_uniform_int(grp, "shading_type", (const int *)&stl->storage->shade_render, 2); + + /* mix stroke factor */ + stl->storage->mix_stroke_factor = (gp_style->flag & GP_STYLE_STROKE_TEX_MIX) ? + gp_style->mix_stroke_factor : + 0.0f; + DRW_shgroup_uniform_float(grp, "mix_stroke_factor", &stl->storage->mix_stroke_factor, 1); } + DRW_shgroup_uniform_vec4(grp, "colormix", gp_style->stroke_rgba, 1); + if ((gpd) && (id > -1)) { stl->shgroups[id].xray_mode = (ob->dtx & OB_DRAWXRAY) ? GP_XRAY_FRONT : GP_XRAY_3DSPACE; DRW_shgroup_uniform_int(grp, "xraymode", &stl->shgroups[id].xray_mode, 1); @@ -703,6 +717,16 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(GPENCIL_e_data *e_data, /* 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); + + /* mix stroke factor */ + stl->shgroups[id].mix_stroke_factor = (gp_style->flag & GP_STYLE_STROKE_TEX_MIX) ? + gp_style->mix_stroke_factor : + 0.0f; + DRW_shgroup_uniform_float(grp, "mix_stroke_factor", &stl->shgroups[id].mix_stroke_factor, 1); + + /* lock rotation of dots and boxes */ + stl->shgroups[id].use_follow_path = (gp_style->flag & GP_STYLE_COLOR_LOCK_DOTS) ? 0 : 1; + DRW_shgroup_uniform_int(grp, "use_follow_path", &stl->shgroups[id].use_follow_path, 1); } else { stl->storage->obj_scale = 1.0f; @@ -724,25 +748,28 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(GPENCIL_e_data *e_data, DRW_shgroup_uniform_vec2(grp, "gradient_s", stl->storage->gradient_s, 1); /* viewport x-ray */ - stl->shgroups[id].is_xray = ((ob) && (ob->dt == OB_WIRE)) ? 1 : stl->storage->is_xray; - DRW_shgroup_uniform_int(grp, "viewport_xray", (const int *)&stl->shgroups[id].is_xray, 1); + DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1); DRW_shgroup_uniform_int(grp, "shading_type", (const int *)&stl->storage->shade_render, 2); + + /* mix stroke factor */ + stl->storage->mix_stroke_factor = (gp_style->flag & GP_STYLE_STROKE_TEX_MIX) ? + gp_style->mix_stroke_factor : + 0.0f; + DRW_shgroup_uniform_float(grp, "mix_stroke_factor", &stl->storage->mix_stroke_factor, 1); + + /* lock rotation of dots and boxes */ + DRW_shgroup_uniform_int(grp, "use_follow_path", &stl->storage->use_follow_path, 1); } + DRW_shgroup_uniform_vec4(grp, "colormix", gp_style->stroke_rgba, 1); + if ((gpd) && (id > -1)) { stl->shgroups[id].xray_mode = (ob->dtx & OB_DRAWXRAY) ? GP_XRAY_FRONT : GP_XRAY_3DSPACE; DRW_shgroup_uniform_int(grp, "xraymode", (const int *)&stl->shgroups[id].xray_mode, 1); - - /* lock rotation of dots and boxes */ - stl->shgroups[id].use_follow_path = (gp_style->flag & GP_STYLE_COLOR_LOCK_DOTS) ? 0 : 1; - DRW_shgroup_uniform_int(grp, "use_follow_path", &stl->shgroups[id].use_follow_path, 1); } else { /* for drawing always on predefined z-depth */ DRW_shgroup_uniform_int(grp, "xraymode", &stl->storage->xray, 1); - - /* lock rotation of dots and boxes */ - DRW_shgroup_uniform_int(grp, "use_follow_path", &stl->storage->use_follow_path, 1); } /* image texture */ diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h index 3add2cb0f1b..2ac1dc3211c 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.h +++ b/source/blender/draw/engines/gpencil/gpencil_engine.h @@ -134,6 +134,8 @@ typedef struct GPENCIL_shgroup { float gradient_f; float gradient_s[2]; + float mix_stroke_factor; + /* color of the wireframe */ float wire_color[4]; /* shading type and mode */ @@ -182,6 +184,8 @@ typedef struct GPENCIL_Storage { float gradient_s[2]; int use_follow_path; + float mix_stroke_factor; + /* Render Matrices and data */ float persmat[4][4], persinv[4][4]; float viewmat[4][4], viewinv[4][4]; 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 c8af822bc9e..204d1962a51 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl @@ -5,6 +5,9 @@ uniform sampler2D myTexture; uniform float gradient_f; uniform vec2 gradient_s; +uniform vec4 colormix; +uniform float mix_stroke_factor; + in vec4 mColor; in vec2 mTexCoord; out vec4 fragColor; @@ -47,7 +50,15 @@ void main() } /* texture */ if (color_type == GPENCIL_COLOR_TEXTURE) { - fragColor = texture2D(myTexture, mTexCoord); + vec4 text_color = texture2D(myTexture, mTexCoord); + if (mix_stroke_factor > 0.0) { + fragColor.rgb = mix(text_color.rgb, colormix.rgb, mix_stroke_factor); + fragColor.a = text_color.a; + } + else { + fragColor = text_color; + } + /* mult both alpha factor to use strength factor with texture */ fragColor.a = min(fragColor.a * mColor.a, fragColor.a); } 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 35d07306361..8964bee69ff 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl @@ -3,6 +3,9 @@ uniform sampler2D myTexture; uniform float gradient_f; +uniform vec4 colormix; +uniform float mix_stroke_factor; + in vec4 mColor; in vec2 mTexCoord; in vec2 uvfac; @@ -46,7 +49,14 @@ void main() /* texture */ if (color_type == GPENCIL_COLOR_TEXTURE) { - fragColor = text_color; + if (mix_stroke_factor > 0.0) { + fragColor.rgb = mix(text_color.rgb, colormix.rgb, mix_stroke_factor); + fragColor.a = text_color.a; + } + else { + fragColor = text_color; + } + /* mult both alpha factor to use strength factor */ fragColor.a = min(fragColor.a * tColor.a, fragColor.a); } |