[Bf-blender-cvs] [4047ed1a9d0] greasepencil-object: GPencil: Add option to mix color with texture

Antonioya noreply at git.blender.org
Thu Apr 18 14:29:38 CEST 2019


Commit: 4047ed1a9d0a40741863844965d0491719d4a5d3
Author: Antonioya
Date:   Thu Apr 18 14:19:00 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rB4047ed1a9d0a40741863844965d0491719d4a5d3

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.

===================================================================

M	release/scripts/startup/bl_ui/properties_material_gpencil.py
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/makesdna/DNA_material_types.h
M	source/blender/makesrna/intern/rna_material.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index e982bea9438..51ad691f1d7 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -146,8 +146,14 @@ class MATERIAL_PT_gpencil_strokecolor(GPMaterialButtonsPanel, Panel):
                     col.prop(gpcolor, "pixel_size", text="UV Factor")
 
                 col.prop(gpcolor, "use_stroke_pattern", text="Use As Pattern")
-
-            if gpcolor.stroke_style == 'SOLID' or gpcolor.use_stroke_pattern is True:
+                if gpcolor.use_stroke_pattern is False:
+                    col.prop(gpcolor, "use_stroke_texture_mix", text="Mix Color")
+                    if gpcolor.use_stroke_texture_mix is True:
+                        col.prop(gpcolor, "mix_stroke_factor", text="Factor")
+
+            if gpcolor.stroke_style == 'SOLID' or \
+                gpcolor.use_stroke_pattern is True or \
+                gpcolor.use_stroke_texture_mix is True:
                 col.prop(gpcolor, "color", text="Color")
 
             if gpcolor.mode in {'DOTS', 'BOX'}:
@@ -203,7 +209,7 @@ class MATERIAL_PT_gpencil_fillcolor(GPMaterialButtonsPanel, Panel):
                 col.prop(gpcolor, "pattern_gridsize", text="Box Size")
 
         # Texture
-        if gpcolor.fill_style == 'TEXTURE' or (gpcolor.texture_mix is True and gpcolor.fill_style == 'SOLID'):
+        if gpcolor.fill_style == 'TEXTURE' or (gpcolor.use_fill_texture_mix is True and gpcolor.fill_style == 'SOLID'):
             col.template_ID(gpcolor, "fill_image", open="image.open")
 
             if gpcolor.fill_style == 'TEXTURE':
@@ -218,9 +224,9 @@ class MATERIAL_PT_gpencil_fillcolor(GPMaterialButtonsPanel, Panel):
             col.prop(gpcolor, "texture_clamp", text="Clip Image")
 
             if gpcolor.use_fill_pattern is False:
-                col.prop(gpcolor, "texture_mix", text="Mix With Color")
+                col.prop(gpcolor, "use_fill_texture_mix", text="Mix With Color")
 
-                if gpcolor.texture_mix is True:
+                if gpcolor.use_fill_texture_mix is True:
                     col.prop(gpcolor, "fill_color", text="Mix Color")
                     col.prop(gpcolor, "mix_factor", text="Mix Factor", slider=True)
 
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 @@ uni

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list