[Bf-blender-cvs] [710601b5d01] greasepencil-refactor: GPencil: Refactor: Support solid mode color modes
Clément Foucault
noreply at git.blender.org
Sat Jan 11 16:13:28 CET 2020
Commit: 710601b5d01057191bae67110355e76ec6e8dc1e
Author: Clément Foucault
Date: Sat Jan 11 16:09:50 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB710601b5d01057191bae67110355e76ec6e8dc1e
GPencil: Refactor: Support solid mode color modes
This should be a 1:1 feature parity with what the workbench do with meshes
objects.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_data.c
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index c35244782cf..bf2204c6f7a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -26,6 +26,8 @@
#include "BKE_image.h"
+#include "BLI_hash.h"
+#include "BLI_math_color.h"
#include "BLI_memblock.h"
#include "GPU_uniformbuffer.h"
@@ -99,6 +101,101 @@ static void gpencil_uv_transform_get(const float ofs[2],
copy_v2_v2(r_uvmat[2], mat[3]);
}
+#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 refered color, not gamma corrected and not per perceptual.
+ * So we lower the threshold a bit. (1.0 / 3.0) */
+ if (color[0] + color[1] + color[2] > 1.1) {
+ add_v3_fl(color, -0.25f);
+ }
+ else {
+ add_v3_fl(color, 0.15f);
+ }
+ CLAMP3(color, 0.0f, 1.0f);
+}
+
+/* Apply all overrides from the solid viewport mode to the GPencil material. */
+static MaterialGPencilStyle *gpencil_viewport_material_overrides(GPENCIL_PrivateData *pd,
+ Object *ob,
+ MaterialGPencilStyle *gp_style)
+{
+ static MaterialGPencilStyle gp_style_tmp;
+
+ switch (pd->v3d_color_type) {
+ case V3D_SHADING_MATERIAL_COLOR:
+ 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;
+ gp_style->stroke_style = GP_MATERIAL_STROKE_STYLE_SOLID;
+ gp_style->fill_style = GP_MATERIAL_FILL_STYLE_SOLID;
+ break;
+ case V3D_SHADING_TEXTURE_COLOR:
+ memcpy(&gp_style_tmp, gp_style, sizeof(*gp_style));
+ gp_style = &gp_style_tmp;
+ if ((gp_style->stroke_style == GP_MATERIAL_STROKE_STYLE_TEXTURE) && (gp_style->sima)) {
+ copy_v4_fl(gp_style->stroke_rgba, 1.0f);
+ gp_style->mix_stroke_factor = 0.0f;
+ }
+ if (((gp_style->fill_style == GP_MATERIAL_FILL_STYLE_TEXTURE) && (gp_style->ima)) ||
+ (gp_style->fill_style == GP_MATERIAL_FILL_STYLE_GRADIENT)) {
+ copy_v4_fl(gp_style->fill_rgba, 1.0f);
+ 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;
+ gp_style->fill_style = GP_MATERIAL_FILL_STYLE_SOLID;
+ copy_v3_v3(gp_style->fill_rgba, pd->v3d_single_color);
+ 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_OBJECT_COLOR:
+ gp_style = &gp_style_tmp;
+ gp_style->stroke_style = GP_MATERIAL_STROKE_STYLE_SOLID;
+ gp_style->fill_style = GP_MATERIAL_FILL_STYLE_SOLID;
+ copy_v4_v4(gp_style->fill_rgba, ob->color);
+ copy_v4_v4(gp_style->stroke_rgba, ob->color);
+ gpencil_shade_color(gp_style->stroke_rgba);
+ break;
+ case V3D_SHADING_VERTEX_COLOR:
+ gp_style = &gp_style_tmp;
+ gp_style->stroke_style = GP_MATERIAL_STROKE_STYLE_SOLID;
+ gp_style->fill_style = GP_MATERIAL_FILL_STYLE_SOLID;
+ copy_v4_fl(gp_style->fill_rgba, 1.0f);
+ copy_v4_fl(gp_style->stroke_rgba, 1.0f);
+ break;
+ default:
+ break;
+ }
+ return gp_style;
+}
+
/**
* Creates a linked list of material pool containing all materials assigned for a given object.
* We merge the material pools together if object does not contain a huge amount of materials.
@@ -150,6 +247,8 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
mat_data->flag |= GP_STROKE_OVERLAP;
}
+ gp_style = gpencil_viewport_material_overrides(pd, ob, gp_style);
+
/* Stroke Style */
if ((gp_style->stroke_style == GP_MATERIAL_STROKE_STYLE_TEXTURE) && (gp_style->sima)) {
bool premul;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 036b4aad7fa..779d7a12b1b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -118,6 +118,9 @@ void GPENCIL_engine_init(void *ved)
(v3d->shading.flag & V3D_SHADING_SCENE_WORLD)) ||
((v3d->shading.type == OB_RENDER) &&
(v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER));
+
+ stl->pd->v3d_color_type = (v3d->shading.type == OB_SOLID) ? v3d->shading.color_type : -1;
+ copy_v3_v3(stl->pd->v3d_single_color, v3d->shading.single_color);
}
stl->pd->use_lighting = (v3d && v3d->shading.type > OB_SOLID);
@@ -377,6 +380,11 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
iter->ubo_lights = (use_lights) ? iter->pd->global_light_pool->ubo :
iter->pd->shadeless_light_pool->ubo;
+ bool overide_vertcol = (iter->pd->v3d_color_type != -1);
+ bool is_vert_col_mode = (iter->pd->v3d_color_type == V3D_SHADING_VERTEX_COLOR);
+ float vert_col_opacity = (overide_vertcol) ? (is_vert_col_mode ? 1.0f : 0.0f) :
+ gpl->vertex_paint_opacity;
+
struct GPUShader *sh = GPENCIL_shader_geometry_get();
iter->grp = DRW_shgroup_create(sh, tgp_layer->geom_ps);
DRW_shgroup_uniform_block_persistent(iter->grp, "gpLightBlock", iter->ubo_lights);
@@ -391,7 +399,7 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
DRW_shgroup_uniform_float_copy(iter->grp, "thicknessScale", object_scale);
DRW_shgroup_uniform_float_copy(iter->grp, "thicknessOffset", (float)gpl->line_change);
DRW_shgroup_uniform_float_copy(iter->grp, "thicknessWorldScale", thickness_scale);
- DRW_shgroup_uniform_float_copy(iter->grp, "vertexColorOpacity", gpl->vertex_paint_opacity);
+ DRW_shgroup_uniform_float_copy(iter->grp, "vertexColorOpacity", vert_col_opacity);
DRW_shgroup_uniform_float_copy(iter->grp, "strokeIndexOffset", iter->stroke_index_offset);
DRW_shgroup_stencil_mask(iter->grp, 0xFF);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 482209723a3..f50c7aaf555 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -269,6 +269,10 @@ typedef struct GPENCIL_PrivateData {
GPUFrameBuffer *scene_fb;
/* Copy of txl->dummy_tx */
GPUTexture *dummy_tx;
+ /* Copy of v3d->shading.single_color. */
+ float v3d_single_color[3];
+ /* Copy of v3d->shading.color_type or -1 to ignore. */
+ int v3d_color_type;
/* Current frame */
int cfra;
/* If we are rendering for final render (F12). */
More information about the Bf-blender-cvs
mailing list