Object ID access in materials

Discussion related to the Engine functionality, implementations and API.
User avatar
B.Y.O.B.
Developer
Posts: 1594
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Object ID access in materials

Post by B.Y.O.B. » Mon Oct 01, 2018 1:46 pm

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.
Attachments
Webp.net-gifmaker.gif
Support LuxCoreRender project with salts and bounties

User avatar
B.Y.O.B.
Developer
Posts: 1594
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Object ID access in materials

Post by B.Y.O.B. » Mon Oct 01, 2018 6:51 pm

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.
Support LuxCoreRender project with salts and bounties

User avatar
B.Y.O.B.
Developer
Posts: 1594
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Object ID access in materials

Post by B.Y.O.B. » Thu Oct 11, 2018 12:48 pm

I have solved both problems.
Attachments
Webp.net-gifmaker.gif
Support LuxCoreRender project with salts and bounties

User avatar
B.Y.O.B.
Developer
Posts: 1594
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Object ID access in materials

Post by B.Y.O.B. » Thu Oct 11, 2018 2:52 pm

It also looks cool if you screw with the hue of a color just slightly.
Attachments
2018-10-11_16-51-46.png
Support LuxCoreRender project with salts and bounties

provisory
Posts: 14
Joined: Wed Aug 01, 2018 4:26 pm

Re: Object ID access in materials

Post by provisory » Thu Oct 11, 2018 6:20 pm

It will be super useful!

marcatore
Posts: 110
Joined: Wed Jan 10, 2018 8:04 am

Re: Object ID access in materials

Post by marcatore » Fri Oct 12, 2018 6:59 am

super useful!!

provisory
Posts: 14
Joined: Wed Aug 01, 2018 4:26 pm

Re: Object ID access in materials

Post by provisory » Fri Oct 12, 2018 12:49 pm

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...

User avatar
B.Y.O.B.
Developer
Posts: 1594
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Object ID access in materials

Post by B.Y.O.B. » Fri Oct 12, 2018 1:05 pm

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.
Support LuxCoreRender project with salts and bounties

provisory
Posts: 14
Joined: Wed Aug 01, 2018 4:26 pm

Re: Object ID access in materials

Post by provisory » Fri Oct 12, 2018 6:43 pm

Currently, none of these can be textured.
Oh, I remembered that 2D Mapping node has inputs for scale, rotation and offset...

provisory
Posts: 14
Joined: Wed Aug 01, 2018 4:26 pm

Re: Object ID access in materials

Post by provisory » Fri Oct 12, 2018 7:06 pm

Oh, I remembered that 2D Mapping node has inputs for scale, rotation and offset...
I mean, I remembered badly

Post Reply