Workbench: Option to use Object color

- added `object_color_type` where the user can set if the collection
determines the color, or the object will be used for the color.
Implemented it as an enum as later this can have a random color option.
- moved OB_LIGHTING_* to DNA_view3d_types and renamed it.
- Fixed some DRY in workbench_materials.c. Can remove more DRY's but
will need to discuss the responsibility of the workbench engine as it
might become part of the eevee renderer.
This commit is contained in:
2018-04-19 09:45:52 +02:00
parent 1f5d51e44e
commit 16fac020e0
14 changed files with 104 additions and 100 deletions

View File

@@ -96,6 +96,7 @@ class COLLECTION_PT_workbench_settings(CollectionButtonsPanel, Panel):
collection_props = collection.engine_overrides['BLENDER_WORKBENCH']
col = layout.column()
col.template_override_property(collection_props, scene_props, "object_color_type")
col.template_override_property(collection_props, scene_props, "object_color")

View File

@@ -907,7 +907,9 @@ class RENDER_PT_workbench_collection_settings(RenderButtonsPanel, Panel):
props = context.scene.collection_properties['BLENDER_WORKBENCH']
col = layout.column()
col.prop(props, "object_color")
col.prop(props, "object_color_type")
if props.object_color_type == 'COLLECTION':
col.prop(props, "object_color")
classes = (

View File

@@ -913,8 +913,8 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
v3d->drawtype_solid = OB_LIGHTING_STUDIO;
v3d->drawtype_wireframe = OB_LIGHTING_STUDIO;
v3d->drawtype_solid = V3D_LIGHTING_STUDIO;
v3d->drawtype_wireframe = V3D_LIGHTING_STUDIO;
/* Assume (demo) files written with 2.8 want to show
* Eevee renders in the viewport. */

View File

@@ -68,24 +68,7 @@ static void workbench_solid_flat_cache_init(void *vedata)
static void workbench_solid_flat_cache_populate(void *vedata, Object *ob)
{
WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
WORKBENCH_StorageList *stl = data->stl;
IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_WORKBENCH);
const float *color = BKE_collection_engine_property_value_get_float_array(props, "object_color");
if (!DRW_object_is_renderable(ob))
return;
struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
WORKBENCH_MaterialData *material;
if (geom) {
/* Depth */
DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat);
/* Solid */
material = workbench_get_or_create_solid_flat_material_data(data, color);
DRW_shgroup_call_add(material->shgrp, geom, ob->obmat);
}
workbench_materials_solid_cache_populate(data, ob, V3D_LIGHTING_FLAT);
}
static void workbench_solid_flat_cache_finish(void *vedata)

View File

@@ -68,24 +68,7 @@ static void workbench_solid_studio_cache_init(void *vedata)
static void workbench_solid_studio_cache_populate(void *vedata, Object *ob)
{
WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
WORKBENCH_StorageList *stl = data->stl;
IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_WORKBENCH);
const float* color = BKE_collection_engine_property_value_get_float_array(props, "object_color");
if (!DRW_object_is_renderable(ob))
return;
struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
WORKBENCH_MaterialData *material;
if (geom) {
/* Depth */
DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat);
/* Solid */
material = workbench_get_or_create_solid_studio_material_data(data, color);
DRW_shgroup_call_add(material->shgrp, geom, ob->obmat);
}
workbench_materials_solid_cache_populate(data, ob, V3D_LIGHTING_STUDIO);
}
static void workbench_solid_studio_cache_finish(void *vedata)

View File

@@ -49,6 +49,7 @@ static void workbench_layer_collection_settings_create(RenderEngine *UNUSED(engi
props->type == IDP_GROUP &&
props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
float default_object_color[3] = {1.0, 1.0, 1.0};
BKE_collection_engine_property_add_int(props, "object_color_type", V3D_OBJECT_COLOR_COLLECTION);
BKE_collection_engine_property_add_float_array(props, "object_color", default_object_color, 3);
}

View File

@@ -55,48 +55,19 @@ static uint get_material_hash(const float color[3])
return r + g * 4096 + b * 4096 * 4096;
}
WORKBENCH_MaterialData *workbench_get_or_create_solid_flat_material_data(WORKBENCH_Data *vedata, const float color[3])
static const float* get_material_solid_color(Object *ob)
{
WORKBENCH_StorageList *stl = vedata->stl;
WORKBENCH_PassList *psl = vedata->psl;
WORKBENCH_PrivateData *wpd = stl->g_data;
IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_WORKBENCH);
int object_color_option = BKE_collection_engine_property_value_get_int(props, "object_color_type");
switch (object_color_option)
{
default:
case V3D_OBJECT_COLOR_COLLECTION:
return BKE_collection_engine_property_value_get_float_array(props, "object_color");
uint hash = get_material_hash(color);
WORKBENCH_MaterialData *material;
material = BLI_ghash_lookup(wpd->material_hash, SET_UINT_IN_POINTER(hash));
if (material == NULL) {
material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), "WORKBENCH_MaterialData");
material->shgrp = DRW_shgroup_create(e_data.solid_flat_sh, psl->solid_pass);
material->color[0] = color[0];
material->color[1] = color[1];
material->color[2] = color[2];
DRW_shgroup_uniform_vec3(material->shgrp, "color", material->color, 1);
BLI_ghash_insert(wpd->material_hash, SET_UINT_IN_POINTER(hash), material);
case V3D_OBJECT_COLOR_OBJECT:
return ob->col;
}
return material;
}
WORKBENCH_MaterialData *workbench_get_or_create_solid_studio_material_data(WORKBENCH_Data *vedata, const float color[3])
{
WORKBENCH_StorageList *stl = vedata->stl;
WORKBENCH_PassList *psl = vedata->psl;
WORKBENCH_PrivateData *wpd = stl->g_data;
uint hash = get_material_hash(color);
WORKBENCH_MaterialData *material;
material = BLI_ghash_lookup(wpd->material_hash, SET_UINT_IN_POINTER(hash));
if (material == NULL) {
material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), "WORKBENCH_MaterialData");
material->shgrp = DRW_shgroup_create(e_data.solid_studio_sh, psl->solid_pass);
material->color[0] = color[0];
material->color[1] = color[1];
material->color[2] = color[2];
DRW_shgroup_uniform_vec3(material->shgrp, "color", material->color, 1);
BLI_ghash_insert(wpd->material_hash, SET_UINT_IN_POINTER(hash), material);
}
return material;
}
void workbench_materials_engine_init(void)
@@ -127,6 +98,44 @@ void workbench_materials_cache_init(WORKBENCH_Data *vedata)
wpd->material_hash = BLI_ghash_ptr_new("Workbench material_hash");
}
void workbench_materials_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob, int lighting_mode)
{
WORKBENCH_StorageList *stl = vedata->stl;
WORKBENCH_PassList *psl = vedata->psl;
WORKBENCH_PrivateData *wpd = stl->g_data;
if (!DRW_object_is_renderable(ob))
return;
struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
WORKBENCH_MaterialData *material;
if (geom) {
/* Depth */
DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat);
/* Solid */
GPUShader *shader = lighting_mode == V3D_LIGHTING_FLAT?e_data.solid_flat_sh:e_data.solid_studio_sh;
const float *color = get_material_solid_color(ob);
uint hash = get_material_hash(color);
WORKBENCH_MaterialData *material;
material = BLI_ghash_lookup(wpd->material_hash, SET_UINT_IN_POINTER(hash));
if (material == NULL) {
material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), "WORKBENCH_MaterialData");
material->shgrp = DRW_shgroup_create(shader, psl->solid_pass);
material->color[0] = color[0];
material->color[1] = color[1];
material->color[2] = color[2];
DRW_shgroup_uniform_vec3(material->shgrp, "color", material->color, 1);
BLI_ghash_insert(wpd->material_hash, SET_UINT_IN_POINTER(hash), material);
}
DRW_shgroup_call_add(material->shgrp, geom, ob->obmat);
}
}
void workbench_materials_cache_finish(WORKBENCH_Data *vedata)
{
WORKBENCH_StorageList *stl = vedata->stl;

View File

@@ -28,6 +28,7 @@
#include "DRW_render.h"
#include "DNA_view3d_types.h"
#define WORKBENCH_ENGINE "BLENDER_WORKBENCH"
@@ -78,8 +79,7 @@ void workbench_solid_materials_free(void);
void workbench_materials_engine_init(void);
void workbench_materials_engine_finish(void);
void workbench_materials_cache_init(WORKBENCH_Data *vedata);
WORKBENCH_MaterialData *workbench_get_or_create_solid_flat_material_data(WORKBENCH_Data *vedata, const float color[3]);
WORKBENCH_MaterialData *workbench_get_or_create_solid_studio_material_data(WORKBENCH_Data *vedata, const float color[3]);
void workbench_materials_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob, int lighting_mode);
void workbench_materials_cache_finish(WORKBENCH_Data *vedata);

View File

@@ -903,10 +903,11 @@ static void drw_engines_enable_from_engine(RenderEngineType *engine_type, int dr
break;
case OB_SOLID:
if (drawtype_solid == OB_LIGHTING_FLAT) {
if (drawtype_solid == V3D_LIGHTING_FLAT) {
use_drw_engine(&draw_engine_workbench_solid_flat);
}
else if (drawtype_solid == OB_LIGHTING_STUDIO) {
}
else if (drawtype_solid == V3D_LIGHTING_STUDIO) {
use_drw_engine(&draw_engine_workbench_solid_studio);
}
@@ -1948,6 +1949,7 @@ void DRW_engines_register(void)
RE_engines_register(NULL, &DRW_engine_viewport_workbench_type);
DRW_engine_register(&draw_engine_workbench_solid_flat);
DRW_engine_register(&draw_engine_workbench_solid_studio);
DRW_engine_register(&draw_engine_object_type);
DRW_engine_register(&draw_engine_edit_armature_type);

View File

@@ -333,8 +333,8 @@ static SpaceLink *view3d_new(const bContext *C)
v3d->gridlines = 16;
v3d->gridsubdiv = 10;
v3d->drawtype = OB_SOLID;
v3d->drawtype_solid = OB_LIGHTING_STUDIO;
v3d->drawtype_texture = OB_LIGHTING_STUDIO;
v3d->drawtype_solid = V3D_LIGHTING_STUDIO;
v3d->drawtype_texture = V3D_LIGHTING_STUDIO;
v3d->gridflag = V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_FLOOR;

View File

@@ -446,12 +446,6 @@ enum {
OB_PAINT = 100, /* temporary used in draw code */
};
enum {
OB_LIGHTING_FLAT = 0,
OB_LIGHTING_STUDIO = 1,
OB_LIGHTING_SCENE = 2
};
/* dtx: flags (short) */
enum {
OB_DRAWBOUNDOX = 1 << 0,

View File

@@ -74,6 +74,16 @@ typedef struct View3DDebug {
} View3DDebug;
/* ********************************* */
enum {
V3D_LIGHTING_FLAT = 0,
V3D_LIGHTING_STUDIO = 1,
V3D_LIGHTING_SCENE = 2
};
enum {
V3D_OBJECT_COLOR_COLLECTION = 0,
V3D_OBJECT_COLOR_OBJECT = 1,
};
typedef struct RegionView3D {

View File

@@ -26,6 +26,7 @@
#include "DNA_scene_types.h"
#include "DNA_layer_types.h"
#include "DNA_view3d_types.h"
#include "BLI_math.h"
#include "BLI_string_utils.h"
@@ -312,6 +313,9 @@ static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_set(PointerRNA *ptr,
#define RNA_LAYER_ENGINE_WORKBENCH_GET_SET_FLOAT_ARRAY(_NAME_, _LEN_) \
RNA_LAYER_ENGINE_GET_SET_ARRAY(float, Workbench, COLLECTION_MODE_NONE, _NAME_, _LEN_)
#define RNA_LAYER_ENGINE_WORKBENCH_GET_SET_INT(_NAME_) \
RNA_LAYER_ENGINE_GET_SET(int, Workbench, COLLECTION_MODE_NONE, _NAME_)
/* mode engines */
#define RNA_LAYER_MODE_OBJECT_GET_SET_FLOAT(_NAME_) \
@@ -359,6 +363,7 @@ RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(hair_brightness_randomness)
/* workbench engine */
/* LayerCollection settings. */
RNA_LAYER_ENGINE_WORKBENCH_GET_SET_FLOAT_ARRAY(object_color, 3)
RNA_LAYER_ENGINE_WORKBENCH_GET_SET_INT(object_color_type)
/* eevee engine */
/* ViewLayer settings. */
@@ -1662,21 +1667,35 @@ static void rna_def_layer_collection_engine_settings_clay(BlenderRNA *brna)
}
#endif /* WITH_CLAY_ENGINE */
/* Workbench engine */
static void rna_def_layer_collection_engine_settings_workbench(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
static const EnumPropertyItem object_color_type_items[] = {
{V3D_OBJECT_COLOR_COLLECTION, "COLLECTION", 0, "Collection", ""},
{V3D_OBJECT_COLOR_OBJECT, "OBJECT", 0, "Object", ""},
{0, NULL, 0, NULL, NULL}
};
srna = RNA_def_struct(brna, "LayerCollectionEngineSettingsWorkbench", "LayerCollectionSettings");
RNA_def_struct_ui_text(srna, "Collections Workbench Engine Settings", "Engine specific settings for this collection");
RNA_def_struct_ui_text(srna, "Collections Workbench Engine Settings", "Workbench specific settings for this collection");
RNA_define_verify_sdna(0); /* not in sdna */
prop = RNA_def_property(srna, "object_color_type", PROP_ENUM, PROP_COLOR);
RNA_def_property_enum_funcs(prop, "rna_LayerEngineSettings_Workbench_object_color_type_get", "rna_LayerEngineSettings_Workbench_object_color_type_set", NULL);
RNA_def_property_enum_items(prop, object_color_type_items);
RNA_def_property_ui_text(prop, "Object Color", "Way colors are given to the Object");
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
prop = RNA_def_property(srna, "object_color", PROP_FLOAT, PROP_COLOR);
RNA_def_property_array(prop, 3);
RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Workbench_object_color_get",
"rna_LayerEngineSettings_Workbench_object_color_set", NULL);
RNA_def_property_ui_text(prop, "Object Color", "Color for Drawing Objects");
RNA_def_property_ui_text(prop, "Collection Color", "Color for Drawing Objects in this Collection");
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
}

View File

@@ -183,15 +183,15 @@ const EnumPropertyItem rna_enum_viewport_shade_items[] = {
};
const EnumPropertyItem rna_enum_viewport_shade_solid_items[] = {
{OB_LIGHTING_FLAT, "FLAT", ICON_SOLID, "Flat Lighting", "Display using flat lighting"},
{OB_LIGHTING_STUDIO, "STUDIO", ICON_SOLID, "Studio Lighting", "Display using studio lighting"},
// {OB_LIGHTING_SCENE, "SCENE", ICON_SOLID, "Scene Lighting", "Display using scene lighting"},
{V3D_LIGHTING_FLAT, "FLAT", ICON_SOLID, "Flat Lighting", "Display using flat lighting"},
{V3D_LIGHTING_STUDIO, "STUDIO", ICON_SOLID, "Studio Lighting", "Display using studio lighting"},
/* {V3D_LIGHTING_SCENE, "SCENE", ICON_SOLID, "Scene Lighting", "Display using scene lighting"}, */
{0, NULL, 0, NULL, NULL}
};
const EnumPropertyItem rna_enum_viewport_shade_texture_items[] = {
{OB_LIGHTING_FLAT, "FLAT", ICON_POTATO, "Flat Lighting", "Display using flat lighting"},
{OB_LIGHTING_STUDIO, "STUDIO", ICON_POTATO, "Studio Lighting", "Display using studio lighting"},
// {OB_LIGHTING_SCENE, "SCENE", ICON_POTATO, "Scene Lighting", "Display using scene lighting"},
{V3D_LIGHTING_FLAT, "FLAT", ICON_POTATO, "Flat Lighting", "Display using flat lighting"},
{V3D_LIGHTING_STUDIO, "STUDIO", ICON_POTATO, "Studio Lighting", "Display using studio lighting"},
/* {V3D_LIGHTING_SCENE, "SCENE", ICON_POTATO, "Scene Lighting", "Display using scene lighting"}, */
{0, NULL, 0, NULL, NULL}
};