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.
This commit is contained in:
Brecht Van Lommel 2022-11-11 12:54:01 +01:00
parent 38430c384a
commit 80f5a5a8aa
Notes: blender-bot 2023-02-14 10:43:47 +01:00
Referenced by issue #100749, Blender LTS: Maintenance Task 3.3
Referenced by issue #101270, Regression: 'Object Info' 'Random' always gives the same seed for instanced bezier curves
1 changed files with 9 additions and 4 deletions

View File

@ -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;