diff options
Diffstat (limited to 'source/blender/draw/engines/workbench/workbench_materials.c')
-rw-r--r-- | source/blender/draw/engines/workbench/workbench_materials.c | 89 |
1 files changed, 49 insertions, 40 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c index 873d24116a1..eafeda324d7 100644 --- a/source/blender/draw/engines/workbench/workbench_materials.c +++ b/source/blender/draw/engines/workbench/workbench_materials.c @@ -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; - - 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); + 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"); + + 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; |