From 80f5a5a8aa12594fb724e9ba45185e13c914f7dd Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 11 Nov 2022 12:54:01 +0100 Subject: Fix T101270: Object Info > Random not unique for nested instances and curves This random number is intended to be unique for every instance, however for some cases with more than one level of nesting this was failing. This also affected curves after they were refactored to use geometry sets. For simple cases the random number is the same as before, however for more complex nesting it will be different than before, changing the render result. --- source/blender/blenkernel/intern/object_dupli.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc index 5efd44c620b..3d35cea1e93 100644 --- a/source/blender/blenkernel/intern/object_dupli.cc +++ b/source/blender/blenkernel/intern/object_dupli.cc @@ -87,6 +87,9 @@ struct DupliContext { Object *obedit; Scene *scene; + /** Root parent object at the scene level. */ + Object *root_object; + /** Immediate parent object in the context. */ Object *object; float space_mat[4][4]; /** @@ -138,6 +141,7 @@ static void init_context(DupliContext *r_ctx, r_ctx->scene = scene; r_ctx->collection = nullptr; + r_ctx->root_object = ob; r_ctx->object = ob; r_ctx->obedit = OBEDIT_FROM_OBACT(ob); r_ctx->instance_stack = &instance_stack; @@ -264,8 +268,9 @@ static DupliObject *make_dupli(const DupliContext *ctx, dob->no_draw = true; } - /* Random number. - * The logic here is designed to match Cycles. */ + /* Random number per instance. + * The root object in the scene, persistent ID up to the instance object, and the instance object + * name together result in a unique random number. */ dob->random_id = BLI_hash_string(dob->ob->id.name + 2); if (dob->persistent_id[0] != INT_MAX) { @@ -277,8 +282,8 @@ static DupliObject *make_dupli(const DupliContext *ctx, dob->random_id = BLI_hash_int_2d(dob->random_id, 0); } - if (ctx->object != ob) { - dob->random_id ^= BLI_hash_int(BLI_hash_string(ctx->object->id.name + 2)); + if (ctx->root_object != ob) { + dob->random_id ^= BLI_hash_int(BLI_hash_string(ctx->root_object->id.name + 2)); } return dob; -- cgit v1.2.3