Workbench: Speed up fo scene with many duplis
authorJeroen Bakker <j.bakker@atmind.nl>
Wed, 6 Jun 2018 06:45:31 +0000 (08:45 +0200)
committerJeroen Bakker <j.bakker@atmind.nl>
Wed, 6 Jun 2018 06:50:12 +0000 (08:50 +0200)
The ObjectID pass was generating per material per dupli a specific
number for the outline what results in a GPU context switch. In spring scene
01-050 a scene with many trees (duplis) generated 28000 GPU materials.

Now only new materials are created when objectid pass is enabled. Also
added a hard limit to the number of objects for the objectid pass (255)
Basically the outline between objects will not be drawn, but it will be
very hard to detect them also.

Also fixed for XRay mode.

source/blender/draw/engines/workbench/workbench_deferred.c
source/blender/draw/engines/workbench/workbench_forward.c

index 285551abb1208c5f4cb202e42aac16cbbf4a7ea0..a91e9ab10dfbc3bb8dff2c3b1c997f37b7a2d735 100644 (file)
@@ -191,7 +191,7 @@ static void select_deferred_shaders(WORKBENCH_PrivateData *wpd)
 static void workbench_init_object_data(ObjectEngineData *engine_data)
 {
        WORKBENCH_ObjectData *data = (WORKBENCH_ObjectData *)engine_data;
-       data->object_id = e_data.next_object_id++;
+       data->object_id = ((e_data.next_object_id++) & 0xff) + 1;
        data->shadow_bbox_dirty = true;
 }
 
@@ -441,18 +441,18 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
 
        /* Solid */
        workbench_material_update_data(wpd, ob, mat, &material_template);
-       material_template.object_id = engine_object_data->object_id;
+       material_template.object_id = OBJECT_ID_PASS_ENABLED(wpd)? engine_object_data->object_id: 1;
        material_template.drawtype = drawtype;
        material_template.ima = ima;
        uint hash = workbench_material_get_hash(&material_template);
-
+       
        material = BLI_ghash_lookup(wpd->material_hash, SET_UINT_IN_POINTER(hash));
        if (material == NULL) {
                material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), __func__);
                material->shgrp = DRW_shgroup_create(
                        drawtype == OB_SOLID ? wpd->prepass_solid_sh : wpd->prepass_texture_sh, psl->prepass_pass);
                DRW_shgroup_stencil_mask(material->shgrp, 0xFF);
-               material->object_id = engine_object_data->object_id;
+               material->object_id = material_template.object_id;
                copy_v4_v4(material->material_data.diffuse_color, material_template.material_data.diffuse_color);
                copy_v4_v4(material->material_data.specular_color, material_template.material_data.specular_color);
                material->material_data.roughness = material_template.material_data.roughness;
index 931ffc6181078fd20c4173d81a64e4bcb415608e..01e10bbefbeabae4d5a6ffc87ac609a4770888c8 100644 (file)
@@ -163,7 +163,7 @@ static char *workbench_build_forward_composite_frag(void)
 static void workbench_init_object_data(ObjectEngineData *engine_data)
 {
        WORKBENCH_ObjectData *data = (WORKBENCH_ObjectData *)engine_data;
-       data->object_id = e_data.next_object_id++;
+       data->object_id = ((e_data.next_object_id++) & 0xff) + 1;
 }
 
 static WORKBENCH_MaterialData *get_or_create_material_data(
@@ -180,7 +180,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
 
        /* Solid */
        workbench_material_update_data(wpd, ob, mat, &material_template);
-       material_template.object_id = engine_object_data->object_id;
+       material_template.object_id = OBJECT_ID_PASS_ENABLED(wpd)? engine_object_data->object_id: 1;
        material_template.drawtype = drawtype;
        material_template.ima = ima;
        uint hash = workbench_material_get_hash(&material_template);