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.
This commit is contained in:
parent
cc9bee9162
commit
2ed2dd7b13
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user