Page MenuHome

Object-linked material slot not working correctly with generated geometry in geometry nodes
Closed, ResolvedPublic


System Information
Operating system: Linux-5.8.0-7630-generic-x86_64-with-glibc2.32 64 Bits
Graphics card: Quadro RTX 6000/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 460.32.03

Blender Version
Broken: version: 3.0.0 Alpha, branch: master, commit date: 2021-05-21 07:43, hash: rBc154b078b529
Worked: last week (no specific hash, sorry)

Short description of error
An object-linked material slot does not properly assign a material to generated geometry. This worked previously and adding an Assign Material node seems to fix it, even though nothing is filled in. I guess this has to do with the evaluated material slot list not behaving as it should.

Exact steps for others to reproduce the error
See this file:

Event Timeline

The issue here is that the number of materials on the geometry is the ground truth (this was mentioned in rB1a81d268a19f2f1402f408ad1dadf92c7a399607). In your example, the generated cylinder has no materials and therefore no material can't be overwritten by the object.
The Material Assign node currently does add a material slot to the mesh, even though it is empty. Because it exists, it can be overwritten by the object.

The proper solution might be to create one empty material slot in the mesh primitive nodes. This material slot is referenced by all faces anyway, because their material_index is 0.
@Hans Goudey (HooglyBoogly) What do you think?

Adding a material slot to newly created meshes is a bit hacky, but it's also simple, and not user-visible, so it seems like a fine solution. We would have to take care to do this for all new meshes, not just the mesh primitives. It's also inconsistent with regular mesh primitive objects.

It would definitely be more complicated, but another solution would be refactoring code so that the information of the number of materials in the object is always available when rendering meshes.
The situation we're in currently where we retrieve materials from the object with a callback except for the length of the material array is a little odd IMO. I don't have a strong opinion about which approach is the best though.

Maybe we could change eevee so that it can read the number of materials from the object, not sure how much needs to be changed for that. Could be simple but might also be a more complex refactor.
Note that this refactor should not only be done for meshes, but for the other types as well.