[Bf-blender-cvs] [4f22e6178e6] blender-v3.3-release: Fix T101270: Object Info > Random not unique for nested instances and curves

Brecht Van Lommel noreply at git.blender.org
Mon Nov 28 14:38:01 CET 2022


Commit: 4f22e6178e62eee448b597cc14ee8b8fa2a63612
Author: Brecht Van Lommel
Date:   Fri Nov 11 12:54:01 2022 +0100
Branches: blender-v3.3-release
https://developer.blender.org/rB4f22e6178e62eee448b597cc14ee8b8fa2a63612

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.

===================================================================

M	source/blender/blenkernel/intern/object_dupli.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc
index 7954dc1340a..44e08a9a62b 100644
--- a/source/blender/blenkernel/intern/object_dupli.cc
+++ b/source/blender/blenkernel/intern/object_dupli.cc
@@ -72,6 +72,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];
 
@@ -112,6 +115,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;
@@ -206,8 +210,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) {
@@ -219,8 +224,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;



More information about the Bf-blender-cvs mailing list