Page 1 of 2

Object ID access in materials

Posted: Mon Oct 01, 2018 1:46 pm
by B.Y.O.B.
Access to objectID in materials can be used to get a different value per object.
This makes it possible to create variation among multiple objects using the same material, for example differently colored rocks in a riverbed, color variation in wooden planks on a floor, etc.

I have added an objectID entry to the hitPoint struct and three new textures to access it.
You can see the changes in this commit on the new_math_textures branch.
The textures are:
  • Color - object ID converted to a color
  • Normalized - object ID converted to a float number in range 0..1
  • Raw - the raw object ID, in range 0 to 0xffffff
In BlendLuxCore they are combined into one node.

Note that I have not written the OpenCL versions of these textures yet.
This stuff will probably not make it into v2.1.

Results so far:

All objects in this image use the same material:
2018-10-01_15-39-54.png
0011.png
All floor tiles use the same material:
school_corridor_objID.jpg

Problems:
  • The object ID is not stable over multiple frames if objects are added/removed between frames or if their order changes. See the attached gif for an example (the particle system adds objects).
  • When the DuplicateObjects functions of LuxCore are used, the object ID is copied. For particle systems in Blender, it would be useful if we could pass a boolean to the functions to choose if object IDs should be copied or if new IDs should be generated for the duplicates.

Re: Object ID access in materials

Posted: Mon Oct 01, 2018 6:51 pm
by B.Y.O.B.
B.Y.O.B. wrote: Mon Oct 01, 2018 1:46 pm The object ID is not stable over multiple frames if objects are added/removed between frames or if their order changes. See the attached gif for an example (the particle system adds objects).
I looked into the Cycles source code to see how they handle this: they hash the object name.

Code: Select all

object->random_id = hash_int_2d(hash_string(object->name.c_str()), 0);
You can actually see the object color change after you rename it and re-render :)

I think I could implement something similar in the Blender addon and would not even have to touch LuxCore source code.

Re: Object ID access in materials

Posted: Thu Oct 11, 2018 12:48 pm
by B.Y.O.B.
I have solved both problems.

Re: Object ID access in materials

Posted: Thu Oct 11, 2018 2:52 pm
by B.Y.O.B.
It also looks cool if you screw with the hue of a color just slightly.

Re: Object ID access in materials

Posted: Thu Oct 11, 2018 6:20 pm
by provisory
It will be super useful!

Re: Object ID access in materials

Posted: Fri Oct 12, 2018 6:59 am
by marcatore
super useful!!

Re: Object ID access in materials

Posted: Fri Oct 12, 2018 12:49 pm
by provisory
Really looking forward to this feature, so I was thinking a lot about it, and I have two questions:

Could you add something like a "seed" parameter?

Is it possible, to get more virtually independent value per object? (For Color and Normalized)
For example:
1. for texture shift X direction
2. for texture shift Y direction
3. for texture rotation
4. for texture flip
5. for hue shift
6. for brightness shift
etc...

Re: Object ID access in materials

Posted: Fri Oct 12, 2018 1:05 pm
by B.Y.O.B.
I think we would need an RNG-node for this, with a seed socket.
You would then feed the object ID into the seed socket.
And the RNG node then generates a sequence of random numbers based on this seed.
provisory wrote: Fri Oct 12, 2018 12:49 pm 1. for texture shift X direction
2. for texture shift Y direction
3. for texture rotation
4. for texture flip
Currently, none of these can be textured.
It is on my wishlist as well, but I'm not sure how difficult it would be to change in the code, and what the performance implications are.

Re: Object ID access in materials

Posted: Fri Oct 12, 2018 6:43 pm
by provisory
Currently, none of these can be textured.
Oh, I remembered that 2D Mapping node has inputs for scale, rotation and offset...

Re: Object ID access in materials

Posted: Fri Oct 12, 2018 7:06 pm
by provisory
Oh, I remembered that 2D Mapping node has inputs for scale, rotation and offset...
I mean, I remembered badly