[Bf-blender-cvs] [2ed2dd7b13a] master: GPencil: Add missing 2.82 Random Layer color removed in refactor

Antonio Vazquez noreply at git.blender.org
Tue Apr 14 12:48:17 CEST 2020


Commit: 2ed2dd7b13a09b1081c8110c245c51bb6b3bac91
Author: Antonio Vazquez
Date:   Tue Apr 14 10:09:38 2020 +0200
Branches: master
https://developer.blender.org/rB2ed2dd7b13a09b1081c8110c245c51bb6b3bac91

GPencil: Add missing 2.82 Random Layer color removed in refactor

Use a single color by object in grease pencil is not practical because is necessary to see all layers.

To tint by layer, the layer tint parameter is used and not the material color as is done in other modes.

This function has been backported from 2.82 because was removed in the 2.83 refactor.

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

M	source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M	source/blender/draw/engines/gpencil/gpencil_draw_data.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index f8f55843a29..1344b649dff 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -33,6 +33,7 @@
 #include "BKE_lib_id.h"
 #include "BKE_object.h"
 
+#include "BLI_hash.h"
 #include "BLI_link_utils.h"
 #include "BLI_memblock.h"
 
@@ -234,6 +235,21 @@ static void gpencil_layer_final_tint_and_alpha_get(const GPENCIL_PrivateData *pd
   *r_alpha *= pd->xray_alpha;
 }
 
+/* Random color by layer. */
+static void gpencil_layer_random_color_get(const Object *ob,
+                                           const bGPDlayer *gpl,
+                                           float r_color[3])
+{
+  const float hsv_saturation = 0.7f;
+  const float hsv_value = 0.6f;
+
+  uint ob_hash = BLI_ghashutil_strhash_p_murmur(ob->id.name);
+  uint gpl_hash = BLI_ghashutil_strhash_p_murmur(gpl->info);
+  float hue = BLI_hash_int_01(ob_hash * gpl_hash);
+  float hsv[3] = {hue, hsv_saturation, hsv_value};
+  hsv_to_rgb_v(hsv, r_color);
+}
+
 GPENCIL_tLayer *gpencil_layer_cache_add(GPENCIL_PrivateData *pd,
                                         const Object *ob,
                                         const bGPDlayer *gpl,
@@ -375,7 +391,16 @@ GPENCIL_tLayer *gpencil_layer_cache_add(GPENCIL_PrivateData *pd,
     DRW_shgroup_uniform_float_copy(grp, "thicknessOffset", (float)gpl->line_change);
     DRW_shgroup_uniform_float_copy(grp, "thicknessWorldScale", thickness_scale);
     DRW_shgroup_uniform_float_copy(grp, "vertexColorOpacity", vert_col_opacity);
-    DRW_shgroup_uniform_vec4_copy(grp, "layerTint", layer_tint);
+
+    /* If random color type, need color by layer. */
+    float gpl_color[4];
+    copy_v4_v4(gpl_color, layer_tint);
+    if (pd->v3d_color_type == V3D_SHADING_RANDOM_COLOR) {
+      gpencil_layer_random_color_get(ob, gpl, gpl_color);
+      gpl_color[3] = 1.0f;
+    }
+    DRW_shgroup_uniform_vec4_copy(grp, "layerTint", gpl_color);
+
     DRW_shgroup_uniform_float_copy(grp, "layerOpacity", layer_alpha);
     DRW_shgroup_stencil_mask(grp, 0xFF);
   }
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index 625af8cec6f..225a8edb208 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -94,18 +94,6 @@ static void gpencil_uv_transform_get(const float ofs[2],
 #define HSV_SATURATION 0.5
 #define HSV_VALUE 0.8
 
-static void gpencil_object_random_color_get(const Object *ob, float r_color[3])
-{
-  /* Duplicated from workbench_material.c */
-  uint hash = BLI_ghashutil_strhash_p_murmur(ob->id.name);
-  if (ob->id.lib) {
-    hash = (hash * 13) ^ BLI_ghashutil_strhash_p_murmur(ob->id.lib->name);
-  }
-  float hue = BLI_hash_int_01(hash);
-  float hsv[3] = {hue, HSV_SATURATION, HSV_VALUE};
-  hsv_to_rgb_v(hsv, r_color);
-}
-
 static void gpencil_shade_color(float color[3])
 {
   /* This is scene refereed color, not gamma corrected and not per perceptual.
@@ -129,6 +117,10 @@ static MaterialGPencilStyle *gpencil_viewport_material_overrides(GPENCIL_Private
 
   switch (color_type) {
     case V3D_SHADING_MATERIAL_COLOR:
+    case V3D_SHADING_RANDOM_COLOR:
+      /* Random uses a random color by layer and this is done using the tint
+       * layer. A simple color by object, like meshes, is not practical in
+       * grease pencil. */
       copy_v4_v4(gp_style_tmp.stroke_rgba, gp_style->stroke_rgba);
       copy_v4_v4(gp_style_tmp.fill_rgba, gp_style->fill_rgba);
       gp_style = &gp_style_tmp;
@@ -152,15 +144,6 @@ static MaterialGPencilStyle *gpencil_viewport_material_overrides(GPENCIL_Private
         gp_style->mix_factor = 0.0f;
       }
       break;
-    case V3D_SHADING_RANDOM_COLOR:
-      gp_style = &gp_style_tmp;
-      gp_style->stroke_style = GP_MATERIAL_STROKE_STYLE_SOLID;
-      gp_style->fill_style = GP_MATERIAL_FILL_STYLE_SOLID;
-      gpencil_object_random_color_get(ob, gp_style->fill_rgba);
-      gp_style->fill_rgba[3] = 1.0f;
-      copy_v4_v4(gp_style->stroke_rgba, gp_style->fill_rgba);
-      gpencil_shade_color(gp_style->stroke_rgba);
-      break;
     case V3D_SHADING_SINGLE_COLOR:
       gp_style = &gp_style_tmp;
       gp_style->stroke_style = GP_MATERIAL_STROKE_STYLE_SOLID;



More information about the Bf-blender-cvs mailing list