Use golden ratio conjugate for Face Sets hue generation
The face set ID is sequential, so implementing this was straightforward. Suggested by Jeroen Bakker Reviewed By: jbakker Differential Revision: https://developer.blender.org/D7123
This commit is contained in:
parent
53c03d4679
commit
b0271c6e40
|
@ -11105,14 +11105,13 @@ static int sculpt_face_sets_randomize_colors_invoke(bContext *C,
|
|||
int totnode;
|
||||
Mesh *mesh = ob->data;
|
||||
|
||||
int new_seed = BLI_hash_int(PIL_check_seconds_timer_i() & UINT_MAX);
|
||||
mesh->face_sets_color_seed = new_seed;
|
||||
mesh->face_sets_color_seed += 1;
|
||||
if (ss->face_sets) {
|
||||
const int random_index = clamp_i(
|
||||
ss->totpoly * BLI_hash_int_01(new_seed), 0, max_ii(0, ss->totpoly - 1));
|
||||
ss->totpoly * BLI_hash_int_01(mesh->face_sets_color_seed), 0, max_ii(0, ss->totpoly - 1));
|
||||
mesh->face_sets_color_default = ss->face_sets[random_index];
|
||||
}
|
||||
BKE_pbvh_face_sets_color_set(pbvh, new_seed, mesh->face_sets_color_default);
|
||||
BKE_pbvh_face_sets_color_set(pbvh, mesh->face_sets_color_seed, mesh->face_sets_color_default);
|
||||
|
||||
BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode);
|
||||
for (int i = 0; i < totnode; i++) {
|
||||
|
|
|
@ -189,15 +189,17 @@ static void gpu_pbvh_batch_init(GPU_PBVH_Buffers *buffers, GPUPrimType prim)
|
|||
* \{ */
|
||||
|
||||
/* Returns the Face Set random color for rendering in the overlay given its ID and a color seed. */
|
||||
#define GOLDEN_RATIO_CONJUGATE 0.618033988749895f
|
||||
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);
|
||||
float random_mod_hue = GOLDEN_RATIO_CONJUGATE * (abs(face_set) + (seed % 10));
|
||||
random_mod_hue = random_mod_hue - floorf(random_mod_hue);
|
||||
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),
|
||||
0.6f + (random_mod_sat * 0.25f),
|
||||
1.0f - (random_mod_val * 0.35f),
|
||||
&rgba[0],
|
||||
&rgba[1],
|
||||
&rgba[2]);
|
||||
|
|
Loading…
Reference in New Issue