[Bf-blender-cvs] [240940c58ca] master: GPencil: New Dots gradient

Antonioya noreply at git.blender.org
Mon Apr 15 10:32:28 CEST 2019


Commit: 240940c58ca3ce65e4bbceebea71dd9d1c2c08bc
Author: Antonioya
Date:   Mon Apr 15 10:32:06 2019 +0200
Branches: master
https://developer.blender.org/rB240940c58ca3ce65e4bbceebea71dd9d1c2c08bc

GPencil: New Dots gradient

This commit adds support for drawing Dots strokes with a gradient factor to get artistic effects like watercolor.

Currently, the option is only supported by Dots materials, and in the future will be added to line strokes, but now there is a limitation on drawing engine and we will keep disabled on Line materials.

Also, added the option to align Dots and Boxes strokes textures aligned with the drawing path to get more fluid strokes.

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

M	release/scripts/startup/bl_ui/properties_material_gpencil.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
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_point_geom.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
M	source/blender/editors/gpencil/annotate_paint.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_merge.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesdna/DNA_material_types.h
M	source/blender/makesrna/intern/rna_brush.c
M	source/blender/makesrna/intern/rna_gpencil.c
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 24ba786f7af..8cb59ceee5c 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -148,6 +148,9 @@ class MATERIAL_PT_gpencil_strokecolor(GPMaterialButtonsPanel, Panel):
             if gpcolor.stroke_style == 'SOLID' or gpcolor.use_stroke_pattern is True:
                 col.prop(gpcolor, "color", text="Color")
 
+            if gpcolor.mode in {'DOTS', 'BOX'}:
+                col.prop(gpcolor, "use_follow_path", text="Follow Drawing Path")
+
 
 class MATERIAL_PT_gpencil_fillcolor(GPMaterialButtonsPanel, Panel):
     bl_label = "Fill"
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 17dd35d9fc4..7c1fa0f9663 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1716,9 +1716,9 @@ class VIEW3D_PT_tools_grease_pencil_brush_option(View3DPanel, Panel):
         layout.use_property_decorate = False
 
         brush = context.tool_settings.gpencil_paint.brush
-        gp_settings = brush.gpencil_settings
 
         if brush is not None:
+            gp_settings = brush.gpencil_settings
             col = layout.column(align=True)
             col.prop(gp_settings, "input_samples")
             col.separator()
@@ -1728,7 +1728,20 @@ class VIEW3D_PT_tools_grease_pencil_brush_option(View3DPanel, Panel):
 
             col.prop(gp_settings, "angle", slider=True)
             col.prop(gp_settings, "angle_factor", text="Factor", slider=True)
+
+            ob = context.object
+            if ob:
+                ma = ob.active_material
+                    
+            if brush.gpencil_settings.material:
+                ma = brush.gpencil_settings.material
+
             col.separator()
+            subcol = col.column(align=True)
+            if ma and ma.grease_pencil.mode != 'DOTS':
+                subcol.enabled = False
+            subcol.prop(gp_settings, "gradient_factor", slider=True)
+            subcol.prop(gp_settings, "gradient_shape")
 
 
 class VIEW3D_PT_tools_grease_pencil_brush_stabilizer(View3DPanel, Panel):
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index ea5605d8ed1..e0bc914dd78 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -304,6 +304,10 @@ void BKE_brush_gpencil_presets(bContext *C)
 	brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
 	brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;
 
+	brush->gpencil_settings->gradient_f = 1.0f;
+	brush->gpencil_settings->gradient_s[0] = 1.0f;
+	brush->gpencil_settings->gradient_s[1] = 1.0f;
+
 	/* Pen brush */
 	brush = BKE_brush_add_gpencil(bmain, ts, "Draw Pen");
 	deft = brush; /* save default brush */
@@ -336,6 +340,10 @@ void BKE_brush_gpencil_presets(bContext *C)
 	brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
 	brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;
 
+	brush->gpencil_settings->gradient_f = 1.0f;
+	brush->gpencil_settings->gradient_s[0] = 1.0f;
+	brush->gpencil_settings->gradient_s[1] = 1.0f;
+
 	/* Ink brush */
 	brush = BKE_brush_add_gpencil(bmain, ts, "Draw Ink");
 	brush->size = 60.0f;
@@ -365,6 +373,10 @@ void BKE_brush_gpencil_presets(bContext *C)
 	brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
 	brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;
 
+	brush->gpencil_settings->gradient_f = 1.0f;
+	brush->gpencil_settings->gradient_s[0] = 1.0f;
+	brush->gpencil_settings->gradient_s[1] = 1.0f;
+
 	/* Curve */
 	custom_curve = brush->gpencil_settings->curve_sensitivity;
 	curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
@@ -408,6 +420,10 @@ void BKE_brush_gpencil_presets(bContext *C)
 	curvemapping_initialize(custom_curve);
 	brush_gpencil_curvemap_reset(custom_curve->cm, 3, GPCURVE_PRESET_INKNOISE);
 
+	brush->gpencil_settings->gradient_f = 1.0f;
+	brush->gpencil_settings->gradient_s[0] = 1.0f;
+	brush->gpencil_settings->gradient_s[1] = 1.0f;
+
 	/* Block Basic brush */
 	brush = BKE_brush_add_gpencil(bmain, ts, "Draw Block");
 	brush->size = 150.0f;
@@ -436,6 +452,10 @@ void BKE_brush_gpencil_presets(bContext *C)
 	brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS;
 	brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR;
 
+	brush->gpencil_settings->gradient_f = 1.0f;
+	brush->gpencil_settings->gradient_s[0] = 1.0f;
+	brush->gpencil_settings->gradient_s[1] = 1.0f;
+
 	/* Marker brush */
 	brush = BKE_brush_add_gpencil(bmain, ts, "Draw Marker");
 	brush->size = 80.0f;
@@ -472,6 +492,10 @@ void BKE_brush_gpencil_presets(bContext *C)
 	curvemapping_initialize(custom_curve);
 	brush_gpencil_curvemap_reset(custom_curve->cm, 4, GPCURVE_PRESET_MARKER);
 
+	brush->gpencil_settings->gradient_f = 1.0f;
+	brush->gpencil_settings->gradient_s[0] = 1.0f;
+	brush->gpencil_settings->gradient_s[1] = 1.0f;
+
 	/* Fill brush */
 	brush = BKE_brush_add_gpencil(bmain, ts, "Fill Area");
 	brush->size = 1.0f;
@@ -495,6 +519,10 @@ void BKE_brush_gpencil_presets(bContext *C)
 
 	brush->gpencil_settings->draw_strength = 1.0f;
 
+	brush->gpencil_settings->gradient_f = 1.0f;
+	brush->gpencil_settings->gradient_s[0] = 1.0f;
+	brush->gpencil_settings->gradient_s[1] = 1.0f;
+
 	/* Soft Eraser brush */
 	brush = BKE_brush_add_gpencil(bmain, ts, "Eraser Soft");
 	brush->size = 30.0f;
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index c204a8128c1..d47b3f20a28 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -467,6 +467,10 @@ bGPDstroke *BKE_gpencil_add_stroke(bGPDframe *gpf, int mat_idx, int totpoints, s
 	bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
 
 	gps->thickness = thickness;
+	gps->gradient_f = 1.0f;
+	gps->gradient_s[0] = 1.0f;
+	gps->gradient_s[1] = 1.0f;
+
 	gps->inittime = 0;
 
 	/* enable recalculation flag by default */
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index ce2345b44db..41b1627e873 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -3110,6 +3110,33 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 				}
 			}
 		}
+
+		/* init grease pencil brush gradients */
+		if (!DNA_struct_elem_find(fd->filesdna, "BrushGpencilSettings", "float", "gradient_f")) {
+			for (Brush *brush = bmain->brushes.first; brush; brush = brush->id.next) {
+				if (brush->gpencil_settings != NULL) {
+					BrushGpencilSettings *gp = brush->gpencil_settings;
+					gp->gradient_f = 1.0f;
+					gp->gradient_s[0] = 1.0f;
+					gp->gradient_s[1] = 1.0f;
+				}
+			}
+		}
+
+		/* init grease pencil stroke gradients */
+		if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "float", "gradient_f")) {
+			for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
+				for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+					for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+						for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+							gps->gradient_f = 1.0f;
+							gps->gradient_s[0] = 1.0f;
+							gps->gradient_s[1] = 1.0f;
+						}
+					}
+				}
+			}
+		}
 	}
 
 	{
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index b72a6ebebbd..3bcc963c966 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -95,6 +95,7 @@ void DRW_gpencil_get_point_geom(GpencilBatchCacheElem *be, bGPDstroke *gps, shor
 		be->color_id = GPU_vertformat_attr_add(&be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
 		be->thickness_id = GPU_vertformat_attr_add(&be->format, "thickness", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
 		be->uvdata_id = GPU_vertformat_attr_add(&be->format, "uvdata", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+		be->prev_pos_id = GPU_vertformat_attr_add(&be->format, "prev_pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
 
 		be->vbo = GPU_vertbuf_create_with_format(&be->format);
 		GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex);
@@ -123,6 +124,26 @@ void DRW_gpencil_get_point_geom(GpencilBatchCacheElem *be, bGPDstroke *gps, shor
 		GPU_vertbuf_attr_set(be->vbo, be->uvdata_id, be->vbo_len, uvdata);
 
 		GPU_vertbuf_attr_set(be->vbo, be->pos_id, be->vbo_len, &pt->x);
+
+		/* use previous point to determine stroke direction */
+		bGPDspoint *pt2 = NULL;
+		if (i == 0) {
+			if (gps->totpoints > 1) {
+				/* extrapolate a point before first point */
+				float fpt[3];
+				pt2 = &gps->points[1];
+				interp_v3_v3v3(fpt, &pt2->x, &pt->x, 1.5f);
+				GPU_vertbuf_attr_set(be->vbo, be->prev_pos_id, be->vbo_len, fpt);
+			}
+			else {
+				GPU_vertbuf_attr_set(be->vbo, be->prev_pos_id, be->vbo_len, &pt->x);
+			}
+		}
+		else {
+			pt2 = &gps->points[i - 1];
+			GPU_vertbuf_attr_set(be->vbo, be->prev_pos_id, be->vbo_len, &pt2->x);
+		}
+
 		be->vbo_len++;
 	}
 }
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 6aefd2a69c5..8ecee86d92b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -532,6 +532,10 @@ 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].gradient_f = gps->gradient_f;
+		copy_v2_v2(stl->shgroups[id].gradient_s, gps->gradient_s);
+		DRW_shgroup_uniform_float(grp, "gradient_f", &stl->shgroups[id].gradient_f, 1);
+
 		/* viewport x-ray */
 		stl->shgroups[id].is_xray = (ob->dt == OB_WIRE) ? 1 : stl->storage->is_xray;
 		DRW_shgroup_uniform_int(grp, "viewport_xray", (const int *)&stl->shgroups[id].is_xray, 1);
@@ -565,6 +569,8 @@ DRWShadingGroup *DRW_gpencil_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list