Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <j.bakker@atmind.nl>2019-04-16 15:00:16 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2019-04-23 13:05:33 +0300
commitee701baff8caf6d184fa245e170c1e67981e2608 (patch)
tree0e84a0829141682cedfdf9770e755a3e9f833282 /source/blender/draw/engines/workbench/workbench_materials.c
parentc9ed39925a51fc421a734027c2ef386157392f3b (diff)
Workbench: Support Active Vertex Color
Currently it is not possible to view the vertex colors of an object. To optimize the workflow, workbench will need to support Vertex Colors. The Vertex Colors is a new option in `shading->color_type`. When objects do not have vertex color, the objects will be rendered with the `V3D_SHADING_OBJECT_COLOR`. In order to support vertex colors in workbench the current texture/solid shading structure is migrated to a primary shaders and fallback shaders. Fix: T57000 Reviewers: brecht, fclem Differential Revision: https://developer.blender.org/D4694
Diffstat (limited to 'source/blender/draw/engines/workbench/workbench_materials.c')
-rw-r--r--source/blender/draw/engines/workbench/workbench_materials.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c
index d73eee37a98..6151c1f54dd 100644
--- a/source/blender/draw/engines/workbench/workbench_materials.c
+++ b/source/blender/draw/engines/workbench/workbench_materials.c
@@ -31,6 +31,7 @@
#include "BLI_hash.h"
#include "DNA_node_types.h"
+#include "DNA_mesh_types.h"
#include "ED_uvedit.h"
@@ -67,7 +68,7 @@ void workbench_material_update_data(WORKBENCH_PrivateData *wpd,
hsv_to_rgb_v(hsv, data->diffuse_color);
copy_v3_v3(data->base_color, data->diffuse_color);
}
- else if (color_type == V3D_SHADING_OBJECT_COLOR) {
+ else if (ELEM(color_type, V3D_SHADING_OBJECT_COLOR, V3D_SHADING_VERTEX_COLOR)) {
copy_v3_v3(data->diffuse_color, ob->color);
copy_v3_v3(data->base_color, data->diffuse_color);
}
@@ -90,9 +91,14 @@ void workbench_material_update_data(WORKBENCH_PrivateData *wpd,
}
}
-char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, bool use_textures, bool is_hair)
+char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd,
+ bool is_uniform_color,
+ bool is_hair)
{
char *str = NULL;
+ bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color;
+ bool use_vertex_colors = (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR) &&
+ !is_uniform_color;
DynStr *ds = BLI_dynstr_new();
@@ -126,6 +132,9 @@ char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, bool use_text
if (NORMAL_VIEWPORT_PASS_ENABLED(wpd)) {
BLI_dynstr_append(ds, "#define NORMAL_VIEWPORT_PASS_ENABLED\n");
}
+ if (use_vertex_colors) {
+ BLI_dynstr_append(ds, "#define V3D_SHADING_VERTEX_COLOR\n");
+ }
if (use_textures) {
BLI_dynstr_append(ds, "#define V3D_SHADING_TEXTURE_COLOR\n");
}
@@ -160,6 +169,7 @@ uint workbench_material_get_hash(WORKBENCH_MaterialData *material_template, bool
result += BLI_ghashutil_uinthash_v4_murmur(input);
result += BLI_ghashutil_uinthash((uint)is_ghost);
+ result += BLI_ghashutil_uinthash(material_template->color_type);
/* add texture reference */
if (material_template->ima) {
@@ -184,9 +194,12 @@ int workbench_material_get_composite_shader_index(WORKBENCH_PrivateData *wpd)
}
int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd,
- bool use_textures,
+ bool is_uniform_color,
bool is_hair)
{
+ bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color;
+ bool use_vertex_colors = (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR) &&
+ !is_uniform_color;
/* NOTE: change MAX_PREPASS_SHADERS accordingly when modifying this function. */
int index = 0;
SET_FLAG_FROM_TEST(index, is_hair, 1 << 0);
@@ -195,32 +208,46 @@ int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd,
SET_FLAG_FROM_TEST(index, NORMAL_VIEWPORT_PASS_ENABLED(wpd), 1 << 3);
SET_FLAG_FROM_TEST(index, MATCAP_ENABLED(wpd), 1 << 4);
SET_FLAG_FROM_TEST(index, use_textures, 1 << 5);
+ SET_FLAG_FROM_TEST(index, use_vertex_colors, 1 << 6);
BLI_assert(index < MAX_PREPASS_SHADERS);
return index;
}
int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd,
- bool use_textures,
+ bool is_uniform_color,
bool is_hair)
{
+ bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color;
+ bool use_vertex_colors = (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR) &&
+ !is_uniform_color;
/* NOTE: change MAX_ACCUM_SHADERS accordingly when modifying this function. */
int index = 0;
/* 2 bits FLAT/STUDIO/MATCAP + Specular highlight */
index = SPECULAR_HIGHLIGHT_ENABLED(wpd) ? 3 : wpd->shading.light;
SET_FLAG_FROM_TEST(index, use_textures, 1 << 2);
- SET_FLAG_FROM_TEST(index, is_hair, 1 << 3);
+ SET_FLAG_FROM_TEST(index, use_vertex_colors, 1 << 3);
+ SET_FLAG_FROM_TEST(index, is_hair, 1 << 4);
/* 1 bits SHADOWS (only facing factor) */
- SET_FLAG_FROM_TEST(index, SHADOW_ENABLED(wpd), 1 << 4);
+ SET_FLAG_FROM_TEST(index, SHADOW_ENABLED(wpd), 1 << 5);
BLI_assert(index < MAX_ACCUM_SHADERS);
return index;
}
-int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd, Image *ima, Object *ob)
+int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd,
+ Image *ima,
+ Object *ob,
+ bool is_sculpt_mode)
{
int color_type = wpd->shading.color_type;
- if ((color_type == V3D_SHADING_TEXTURE_COLOR && ima == NULL) || (ob->dt < OB_TEXTURE)) {
+ const Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL;
+
+ if ((color_type == V3D_SHADING_TEXTURE_COLOR && (ima == NULL || is_sculpt_mode)) ||
+ (ob->dt < OB_TEXTURE)) {
color_type = V3D_SHADING_MATERIAL_COLOR;
}
+ if (color_type == V3D_SHADING_VERTEX_COLOR && (me == NULL || me->mloopcol == NULL)) {
+ color_type = V3D_SHADING_OBJECT_COLOR;
+ }
return color_type;
}
@@ -264,7 +291,7 @@ void workbench_material_shgroup_uniform(WORKBENCH_PrivateData *wpd,
return;
}
- if (workbench_material_determine_color_type(wpd, material->ima, ob) ==
+ if (workbench_material_determine_color_type(wpd, material->ima, ob, false) ==
V3D_SHADING_TEXTURE_COLOR) {
ImBuf *ibuf = BKE_image_acquire_ibuf(material->ima, material->iuser, NULL);
const bool do_color_correction = wpd->use_color_management &&