[Bf-blender-cvs] [a540d16ee82] master: Cleanup: Move Face Sets random color generation to its own function

Pablo Dobarro noreply at git.blender.org
Mon Mar 9 19:14:39 CET 2020


Commit: a540d16ee82e6c91d76fdfea8c0b90b922ece4d9
Author: Pablo Dobarro
Date:   Fri Mar 6 13:44:06 2020 +0100
Branches: master
https://developer.blender.org/rBa540d16ee82e6c91d76fdfea8c0b90b922ece4d9

Cleanup: Move Face Sets random color generation to its own function

This way we can change the color generation easily if we want to improve
it in the future. I also added more values to randomize a little bit the
saturation and value of the colors, as previously it was too easy to get
similar colors when creating new faces, forcing you to use the randomize
colors more than necessary.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D7042

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

M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 09d97dcdb84..6671296db2a 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -188,6 +188,22 @@ static void gpu_pbvh_batch_init(GPU_PBVH_Buffers *buffers, GPUPrimType prim)
 /** \name Mesh PBVH
  * \{ */
 
+/* Returns the Face Set random color for rendering in the overlay given its ID and a color seed. */
+static void face_set_overlay_color_get(const int face_set, const int seed, uchar *r_color)
+{
+  float rgba[4];
+  const float random_mod_hue = BLI_hash_int_01(abs(face_set) + seed);
+  const float random_mod_sat = BLI_hash_int_01(abs(face_set) + seed + 1);
+  const float random_mod_val = BLI_hash_int_01(abs(face_set) + seed + 2);
+  hsv_to_rgb(random_mod_hue,
+             0.45f + (random_mod_sat * 0.35f),
+             1.0f - (random_mod_val * 0.45f),
+             &rgba[0],
+             &rgba[1],
+             &rgba[2]);
+  rgba_float_to_uchar(r_color, rgba);
+}
+
 /* Threaded - do not call any functions that use OpenGL calls! */
 void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
                                   const MVert *mvert,
@@ -251,14 +267,8 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
         for (uint i = 0; i < buffers->face_indices_len; i++) {
           if (show_face_sets) {
             const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
-            float rgba[4];
-            hsv_to_rgb(BLI_hash_int_01(abs(sculpt_face_sets[lt->poly]) + face_sets_color_seed),
-                       0.65f,
-                       1.0f,
-                       &rgba[0],
-                       &rgba[1],
-                       &rgba[2]);
-            rgba_float_to_uchar(face_set_color, rgba);
+            face_set_overlay_color_get(
+                sculpt_face_sets[lt->poly], face_sets_color_seed, face_set_color);
           }
           for (int j = 0; j < 3; j++) {
             const int vidx = face_vert_indices[i][j];
@@ -315,14 +325,8 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
 
           uchar face_set_color[4] = {UCHAR_MAX, UCHAR_MAX, UCHAR_MAX, UCHAR_MAX};
           if (show_face_sets) {
-            float rgba[4];
-            hsv_to_rgb(BLI_hash_int_01(abs(sculpt_face_sets[lt->poly]) + face_sets_color_seed),
-                       0.65f,
-                       1.0f,
-                       &rgba[0],
-                       &rgba[1],
-                       &rgba[2]);
-            rgba_float_to_uchar(face_set_color, rgba);
+            face_set_overlay_color_get(
+                sculpt_face_sets[lt->poly], face_sets_color_seed, face_set_color);
           }
 
           float fmask = 0.0f;



More information about the Bf-blender-cvs mailing list