Fix T51931: VBO not updating when UVs are added to shader node tree

UVs need specific data in the VBO, which is not computed unless the
shaders assigned to the mesh actually use UVs. When adding UVs to the
shader, the VBOs were not being recomputed to include the required data.

This adds a DEG relation between the shader and the mesh, and recomputes
the required data if the shader changed.

Thanks Sergey, for all the DEG stuff...
This commit is contained in:
2017-07-10 14:43:57 +02:00
parent d33cacf7e4
commit 45897f12f8
9 changed files with 56 additions and 4 deletions

View File

@@ -406,6 +406,7 @@ enum {
BKE_MESH_BATCH_DIRTY_ALL = 0,
BKE_MESH_BATCH_DIRTY_SELECT,
BKE_MESH_BATCH_DIRTY_NOCHECK,
BKE_MESH_BATCH_DIRTY_SHADING,
};
void BKE_mesh_batch_cache_dirty(struct Mesh *me, int mode);
void BKE_mesh_batch_cache_free(struct Mesh *me);

View File

@@ -200,6 +200,8 @@ void BKE_object_eval_cloth(struct EvaluationContext *eval_ctx,
struct Scene *scene,
struct Object *object);
void BKE_object_eval_update_shading(struct EvaluationContext *eval_ctx,
struct Object *object);
void BKE_object_handle_data_update(struct EvaluationContext *eval_ctx,
struct Scene *scene,

View File

@@ -401,3 +401,11 @@ void BKE_object_eval_cloth(EvaluationContext *UNUSED(eval_ctx), Scene *scene, Ob
DEBUG_PRINT("%s on %s\n", __func__, object->id.name);
BKE_ptcache_object_reset(scene, object, PTCACHE_RESET_DEPSGRAPH);
}
void BKE_object_eval_update_shading(EvaluationContext *UNUSED(eval_ctx), Object *object)
{
DEBUG_PRINT("%s on %s\n", __func__, object->id.name);
if (object->type == OB_MESH) {
BKE_mesh_batch_cache_dirty(object->data, BKE_MESH_BATCH_DIRTY_SHADING);
}
}

View File

@@ -781,10 +781,19 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
}
/* materials */
for (int a = 1; a <= ob->totcol; a++) {
Material *ma = give_current_material(ob, a);
if (ma != NULL) {
build_material(ma);
if (ob->totcol != 0) {
if (ob->type == OB_MESH) {
add_operation_node(&ob->id,
DEG_NODE_TYPE_SHADING,
function_bind(BKE_object_eval_update_shading, _1, ob),
DEG_OPCODE_SHADING);
}
for (int a = 1; a <= ob->totcol; a++) {
Material *ma = give_current_material(ob, a);
if (ma != NULL) {
build_material(ma);
}
}
}

View File

@@ -1448,6 +1448,15 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje
Material *ma = give_current_material(ob, a);
if (ma != NULL) {
build_material(ma);
if (ob->type == OB_MESH) {
OperationKey material_key(&ma->id,
DEG_NODE_TYPE_SHADING,
DEG_OPCODE_PLACEHOLDER,
"Material Update");
OperationKey shading_key(&ob->id, DEG_NODE_TYPE_SHADING, DEG_OPCODE_SHADING);
add_relation(material_key, shading_key, "Material Update");
}
}
}
}

View File

@@ -129,6 +129,8 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
STRINGIFY_OPCODE(COPY_ON_WRITE);
STRINGIFY_OPCODE(SHADING);
case DEG_NUM_OPCODES: return "SpecialCase";
#undef STRINGIFY_OPCODE
}

View File

@@ -217,6 +217,9 @@ typedef enum eDepsOperation_Code {
/* Copy on Write ------------------------- */
DEG_OPCODE_COPY_ON_WRITE,
/* Shading operations ------------------------- */
DEG_OPCODE_SHADING,
DEG_NUM_OPCODES,
} eDepsOperation_Code;

View File

@@ -239,6 +239,14 @@ void IDDepsNode::tag_update(Depsgraph *graph)
do_component_tag = true;
}
}
else if (comp_node->type == DEG_NODE_TYPE_SHADING) {
/* TODO(sergey): For until we properly handle granular flags for DEG_id_tag_update()
* we skip flushing here to keep Luca happy.
*/
if (GS(id_orig->name) != ID_MA) {
do_component_tag = false;
}
}
if (do_component_tag) {
comp_node->tag_update(graph);
}

View File

@@ -1598,6 +1598,16 @@ void DRW_mesh_batch_cache_dirty(Mesh *me, int mode)
case BKE_MESH_BATCH_DIRTY_NOCHECK:
cache->is_really_dirty = true;
break;
case BKE_MESH_BATCH_DIRTY_SHADING:
GWN_VERTBUF_DISCARD_SAFE(cache->shaded_triangles_data);
if (cache->shaded_triangles) {
for (int i = 0; i < cache->mat_len; ++i) {
GWN_BATCH_DISCARD_SAFE(cache->shaded_triangles[i]);
}
}
MEM_SAFE_FREE(cache->shaded_triangles);
break;
default:
BLI_assert(0);
}