[a882debee08] master: Fix T75161: Random UV doesn´t work with fats drawing

Antonio Vazquez noreply at git.blender.org
Sat Mar 28 15:08:29 CET 2020


Commit: a882debee0800049e36639bfb3af115e72791b0c
Author: Antonio Vazquez
Date:   Sat Mar 28 15:08:13 2020 +0100
Branches: master
https://developer.blender.org/rBa882debee0800049e36639bfb3af115e72791b0c

Fix T75161: Random UV doesn´t work with fats drawing

Also fixed T75162

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

M	source/blender/editors/gpencil/gpencil_paint.c

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

diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 5ccd8843a3f..1a169f9ec89 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -30,6 +30,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_hash.h"
 #include "BLI_math.h"
 #include "BLI_math_geom.h"
 #include "BLI_rand.h"
@@ -486,6 +487,7 @@ static void gp_stroke_convertcoords(tGPsdata *p, const float mval[2], float out[
 /* Apply jitter to stroke point. */
 static void gp_brush_jitter(bGPdata *gpd, tGPspoint *pt, const float amplitude)
 {
+  const float axis[2] = {0.0f, 1.0f};
   /* Jitter is applied perpendicular to the mouse movement vector (2D space). */
   float mvec[2];
   /* Mouse movement in ints -> floats. */
@@ -493,16 +495,15 @@ static void gp_brush_jitter(bGPdata *gpd, tGPspoint *pt, const float amplitude)
     tGPspoint *pt_prev = pt - 1;
     sub_v2_v2v2(mvec, &pt->x, &pt_prev->x);
     normalize_v2(mvec);
+    /* Rotate mvec by 90 degrees... */
+    float angle = angle_v2v2(mvec, axis);
+    /* Reduce noise in the direction of the stroke. */
+    mvec[0] *= cos(angle);
+    mvec[1] *= sin(angle);
+
+    /* Scale by displacement amount, and apply. */
+    madd_v2_v2fl(&pt->x, mvec, amplitude * 10.0f);
   }
-  else {
-    mvec[0] = 0.0f;
-    mvec[1] = 0.0f;
-  }
-  /* Rotate mvec by 90 degrees... */
-  SWAP(float, mvec[0], mvec[1]);
-  mvec[0] -= mvec[0];
-  /* Scale by displacement amount, and apply. */
-  madd_v2_v2fl(&pt->x, mvec, amplitude);
 }
 
 /* apply pressure change depending of the angle of the stroke to simulate a pen with shape */
@@ -788,8 +789,10 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
       }
       /* apply randomness to uv texture rotation */
       if (brush_settings->uv_random > 0.0f) {
-        float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
-        pt->uv_rot += rand * M_PI * brush_settings->uv_random;
+        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 */
@@ -3141,7 +3144,7 @@ static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
   if (gpd->runtime.sbuffer_used < 3) {
     return;
   }
-
+  BrushGpencilSettings *brush_settings = p->brush->gpencil_settings;
   int idx_prev = gpd->runtime.sbuffer_used;
 
   /* Add space for new arc points. */
@@ -3206,6 +3209,27 @@ static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
     pt->pressure = pt_prev->pressure;
     pt->strength = pt_prev->strength;
 
+    /* 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 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 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 + i)) *
+                       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);
+    }
+
     a += step;
   }
 }



More information about the Bf-blender-cvs mailing list