Maniphest T93177

set material index is completely broken.
Closed, Archived

Assigned To
None
Authored By
michael campbell (3di)
Nov 18 2021, 1:31 AM
Tags
  • BF Blender
  • Geometry Nodes
Subscribers
Jacques Lucke (JacquesLucke)
michael campbell (3di)

Description

System Information
Operating system: Windows-10-10.0.19042-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 472.12

Blender Version
Broken: version: 3.1.0 Alpha, branch: master, commit date: 2021-11-11 18:53, hash: rB0533f2851e7e
Worked: (newest version of Blender that worked as expected)

open below file. All specified material indexes are replaced by random values. Even two elements set to the same value, result in differing material id's in the spreadsheet and both render with different materials.

Event Timeline

michael campbell (3di) created this task.Nov 18 2021, 1:31 AM
michael campbell (3di) added a project: Geometry Nodes.
michael campbell (3di) added a comment.EditedNov 18 2021, 1:56 AM

Additionally, if the original geometry is not connected to the top of the multi input of the join node, then all material indexes are set to 0. I'm guessing this is a safety measure to make sure that if materials aren't present in the materials shader panel, then everything will revert to 0. This is a terrible idea considering the materials can be added to the node tree at any point. This should always be left at whatever the user sets it to rather than assigning it a 0 if there's no material with that index currently.

Below image shows that plugging the original mesh into the bottom of the join node results in the top two mesh's being given a material ID of zero instead of what was specified. This is bad, but additonally, even though there is a material with ID of 0....no material is rendered (middle 4 cubes).

Jacques Lucke (JacquesLucke) closed this task as Archived.EditedNov 18 2021, 3:26 PM
Jacques Lucke (JacquesLucke) added a subscriber: Jacques Lucke (JacquesLucke).

I think the Set Material Index node is working just fine. The thing that is confusing you is the behavior of the Join Geometry node. The Join Geometry node can change material indices. This is necessary so that it can produce the correct behavior when joining multiple meshes that have different materials (but use the same material indices).

You have two main options:

  • Use the Set Material node, which does what you want. The materials will be propagated correctly by the Join Geometry node. This is the preferred solution. Just don't use material indices directly.
  • Set the material indices after the Join Geometry node using selections (still need to make sure that the final geometry actually contains the materials, e.g. by overriding them on the object).

We could maybe have an option in the Join Geometry node to remove all materials and not touch material indices, but that is outside of the scope of a bug report.

michael campbell (3di) added a comment.EditedNov 18 2021, 5:01 PM

Hey @Jacques Lucke (JacquesLucke). I can understand the need to change material indices and associated attributes where conflicts arise from merged objects, but they should always be given unused slots and leave any tree specified material indexes alone (it would be nice to show this relationship in the spreadsheet, perhaps have the material name in brackets beside the material index). In the case above there are no material conflicts, so can you explain further why it needs to set both material indices to 0 if there are no conflicts?

michael campbell (3di) added a comment.EditedNov 18 2021, 5:10 PM

@Jacques Lucke (JacquesLucke) for example here. I'm not sure if you've looked at the file properly. But below you can see there are no conflicts, yet the join node has created a third empty material and changed the attribute we specified as 0 to 2..so instead of getting the existing checkered material which has mat index 0, it gets a non existent material...

michael campbell (3di) added a comment.EditedNov 18 2021, 5:16 PM

@Jacques Lucke (JacquesLucke) and here, again, no conflicts, but again it's changed all specified material indices to 0. This is because if the materials don't exist on the branch connected to the top of the multi input socket, then it incorrectly thinks there are no materials available on the other branches or at the object level, and breaks everything. Maybe it could check all branches before deciding on availability? And if all branches have no materials, then perhaps it should check the object level materials (from the properties panel)?

Jacques Lucke (JacquesLucke) added a comment.Nov 18 2021, 5:17 PM

The join geometry node is currently allowed to change the material indices however it wants as long as the materials are kept intact (not necessarily the material indices). I could go into the code to figure out why it is doing exactly what it is doing, but that would not fix anything. It's perfectly valid for the Join Geometry node to reorder the materials even if that is not absolutely necessary.
As said, we could have a boolean input to disable this special material handling, but I don't think that would be a better workflow in practice.