[Bf-blender-cvs] [8425ed4288b] greasepencil-object: GPencil: Add Pressure, Strength and UV randomness at stroke level

Antonio Vazquez noreply at git.blender.org
Tue Apr 21 16:28:07 CEST 2020


Commit: 8425ed4288bb2a754c70ecd9b7bf937978f65cd1
Author: Antonio Vazquez
Date:   Tue Apr 21 16:27:56 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB8425ed4288bb2a754c70ecd9b7bf937978f65cd1

GPencil: Add Pressure, Strength and UV randomness at stroke level

Instead to random at point level, a general random by stroke is generated.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 7960e38fdb8..58bb94242a5 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -81,15 +81,15 @@ def gpencil_active_brush_settings_simple(context, layout):
     col.enabled = mode == 'VERTEXCOLOR'
     row = col.row(align=True)
     row.prop(gp_settings, "random_hue_factor", slider=True)
-    row.prop(gp_settings, "use_stroke_random_hue", text="", icon='MOD_THICKNESS')
+    row.prop(gp_settings, "use_stroke_random_hue", text="", icon='GP_SELECT_STROKES')
 
     row = col.row(align=True)
     row.prop(gp_settings, "random_saturation_factor", slider=True)
-    row.prop(gp_settings, "use_stroke_random_sat", text="", icon='MOD_THICKNESS')
+    row.prop(gp_settings, "use_stroke_random_sat", text="", icon='GP_SELECT_STROKES')
 
     row = col.row(align=True)
     row.prop(gp_settings, "random_value_factor", slider=True)
-    row.prop(gp_settings, "use_stroke_random_val", text="", icon='MOD_THICKNESS')
+    row.prop(gp_settings, "use_stroke_random_val", text="", icon='GP_SELECT_STROKES')
 
 
 # XXX: To be replaced with active tools
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 96efbbcc1db..60ec155d6af 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1619,28 +1619,39 @@ class VIEW3D_PT_tools_grease_pencil_brush_random(View3DPanel, Panel):
         col = layout.column()
         col.active = gp_settings.use_settings_random
 
-        col.prop(gp_settings, "random_pressure", text="Pressure", slider=True)
-        col.prop(gp_settings, "random_strength", text="Strength", slider=True)
-        col.prop(gp_settings, "uv_random", text="UV", slider=True)
+        row = col.row(align=True)
+        row.prop(gp_settings, "random_pressure", text="Pressure", slider=True)
+        row.prop(gp_settings, "use_stroke_random_pressure", text="", icon='GP_SELECT_STROKES')
 
         row = col.row(align=True)
-        row.prop(gp_settings, "pen_jitter", slider=True)
-        row.prop(gp_settings, "use_jitter_pressure", text="", icon='STYLUS_PRESSURE')
+        row.prop(gp_settings, "random_strength", text="Strength", slider=True)
+        row.prop(gp_settings, "use_stroke_random_strength", text="", icon='GP_SELECT_STROKES')
 
-        col = layout.column()
-        col.enabled = mode == 'VERTEXCOLOR' and gp_settings.use_settings_random
-        col.separator()
         row = col.row(align=True)
+        row.prop(gp_settings, "uv_random", text="UV", slider=True)
+        row.prop(gp_settings, "use_stroke_random_uv", text="", icon='GP_SELECT_STROKES')
+
+        col.separator()
+
+        col1 = col.column(align=True)
+        col1.enabled = mode == 'VERTEXCOLOR' and gp_settings.use_settings_random
+        row = col1.row(align=True)
         row.prop(gp_settings, "random_hue_factor", slider=True)
-        row.prop(gp_settings, "use_stroke_random_hue", text="", icon='MOD_THICKNESS')
+        row.prop(gp_settings, "use_stroke_random_hue", text="", icon='GP_SELECT_STROKES')
 
-        row = col.row(align=True)
+        row = col1.row(align=True)
         row.prop(gp_settings, "random_saturation_factor", slider=True)
-        row.prop(gp_settings, "use_stroke_random_sat", text="", icon='MOD_THICKNESS')
+        row.prop(gp_settings, "use_stroke_random_sat", text="", icon='GP_SELECT_STROKES')
 
-        row = col.row(align=True)
+        row = col1.row(align=True)
         row.prop(gp_settings, "random_value_factor", slider=True)
-        row.prop(gp_settings, "use_stroke_random_val", text="", icon='MOD_THICKNESS')
+        row.prop(gp_settings, "use_stroke_random_val", text="", icon='GP_SELECT_STROKES')
+
+        col.separator()
+
+        row = col.row(align=True)
+        row.prop(gp_settings, "pen_jitter", slider=True)
+        row.prop(gp_settings, "use_jitter_pressure", text="", icon='STYLUS_PRESSURE')
 
 
 # Grease Pencil drawingcurves
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 09fa367a933..42d70b268f3 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -68,6 +68,14 @@ struct PropertyRNA;
 
 /* Internal Operator-State Data ------------------------ */
 
+/** Random settings by stroke */
+typedef struct GpRandomSettings {
+  float hsv[3];
+  float pressure;
+  float strength;
+  float uv;
+} GpRandomSettings;
+
 /* Temporary draw data (no draw manager mode) */
 typedef struct tGPDdraw {
   struct RegionView3D *rv3d;   /* region to draw */
@@ -231,8 +239,8 @@ typedef struct tGPDprimitive {
   /** size in pixels for uv calculation */
   float totpixlen;
 
-  /** Random vertex color by stroke */
-  float gps_random_color[3];
+  /** Random settings by stroke */
+  GpRandomSettings random_settings;
 
 } tGPDprimitive;
 
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 890c8d220b1..a70067500b0 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -256,8 +256,8 @@ typedef struct tGPsdata {
 
   ReportList *reports;
 
-  /** Random vertex color by stroke */
-  float gps_random_color[3];
+  /** Random settings by stroke */
+  GpRandomSettings random_settings;
 
 } tGPsdata;
 
@@ -691,6 +691,55 @@ static void gp_smooth_segment(bGPdata *gpd, const float inf, int from_idx, int t
   }
 }
 
+static void gp_apply_randomness(tGPsdata *p,
+                                BrushGpencilSettings *brush_settings,
+                                tGPspoint *pt,
+                                const bool press,
+                                const bool strength,
+                                const bool uv)
+{
+  bGPdata *gpd = p->gpd;
+  GpRandomSettings random_settings = p->random_settings;
+
+  /* Apply randomness to pressure. */
+  if ((brush_settings->draw_random_press > 0.0f) && (press)) {
+    if ((brush_settings->flag2 & GP_BRUSH_USE_PRESS_AT_STROKE) == 0) {
+      float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
+      pt->pressure *= 1.0 + rand * 2.0 * brush_settings->draw_random_press;
+    }
+    else {
+      pt->pressure *= 1.0 + random_settings.pressure * brush_settings->draw_random_press;
+    }
+    CLAMP(pt->pressure, GPENCIL_STRENGTH_MIN, 1.0f);
+  }
+
+  /* Apply randomness to color strength. */
+  if ((brush_settings->draw_random_strength) && (strength)) {
+    if ((brush_settings->flag2 & GP_BRUSH_USE_STRENGTH_AT_STROKE) == 0) {
+      float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
+      pt->strength *= 1.0 + rand * brush_settings->draw_random_strength;
+    }
+    else {
+      pt->strength *= 1.0 + random_settings.strength * brush_settings->draw_random_strength;
+    }
+    CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
+  }
+
+  /* Apply randomness to uv texture rotation. */
+  if ((brush_settings->uv_random > 0.0f) && (uv)) {
+    if ((brush_settings->flag2 & GP_BRUSH_USE_UV_AT_STROKE) == 0) {
+      float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used)) * 2.0f -
+                   1.0f;
+      pt->uv_rot += rand * M_PI_2 * brush_settings->uv_random;
+    }
+    else {
+      pt->uv_rot += random_settings.uv * M_PI_2 * brush_settings->uv_random;
+    }
+
+    CLAMP(pt->uv_rot, -M_PI_2, M_PI_2);
+  }
+}
+
 /* add current stroke-point to buffer (returns whether point was successfully added) */
 static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure, double curtime)
 {
@@ -749,8 +798,12 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
     }
 
     /* Set vertex colors for buffer. */
-    ED_gpencil_sbuffer_vertex_color_set(
-        p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material, p->gps_random_color);
+    ED_gpencil_sbuffer_vertex_color_set(p->depsgraph,
+                                        p->ob,
+                                        p->scene->toolsettings,
+                                        p->brush,
+                                        p->material,
+                                        p->random_settings.hsv);
 
     /* get pointer to destination point */
     pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used);
@@ -785,26 +838,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
         const float fac = rand * square_f(exp_factor) * jitpress;
         gp_brush_jitter(gpd, pt, fac);
       }
-      /* apply randomness to pressure */
-      if (brush_settings->draw_random_press > 0.0f) {
-        float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
-        pt->pressure *= 1.0 + rand * 2.0 * brush_settings->draw_random_press;
-        CLAMP(pt->pressure, GPENCIL_STRENGTH_MIN, 1.0f);
-      }
-      /* apply randomness to uv texture rotation */
-      if (brush_settings->uv_random > 0.0f) {
-        float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used)) *
-                         2.0f -
-                     1.0f;
-        pt->uv_rot += rand * M_PI_2 * brush_settings->uv_random;
-        CLAMP(pt->uv_rot, -M_PI_2, M_PI_2);
-      }
-      /* apply randomness to color strength */
-      if (brush_settings->draw_random_strength) {
-        float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
-        pt->strength *= 1.0 + rand * brush_settings->draw_random_strength;
-        CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
-      }
+
+      /* Apply other randomness. */
+      gp_apply_randomness(p, brush_settings, pt, true, true, true);
     }
 
     /* apply angle of stroke to brush size */
@@ -3049,7 +3085,7 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
     p = op->customdata;
   }
   /* Init random vertex color. */
-  ED_gpencil_init_random_color(p->brush, event->mval, p->gps_random_color);
+  ED_gpencil_init_random_settings(p

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list