3
$\begingroup$

I need to be able to some how color each instance in a geometry nodes tree a different color.

Each instance in the geometry nodes network is loose geometry. If I apply the geometry nodes modifier and then separate the geometry by loose parts, I can get the effect I want in the shader editor by using the Object Info node's Random output, as shown below:

enter image description here

However, I need to be able to get the same result without applying the geometry nodes modifier and separating the loose parts.

I see that there's a way to assign the material index for a piece of geometry, but it seems like this index applies for the entire mesh.

enter image description here

Is there any way I can pump out the ID for each instance and somehow use that in the shading editor?

I've looked at these two questions but I haven't found anything that has worked (or at least I haven't figured out how to make them work yet). Control Instance Color with Geometry Nodes

Geometry nodes: Assign random material to instances on points

I've also watched through this video by Entagma, but it seems that Geometry Nodes' attribute system has changed such that I'm not really certain how I would apply the principles from that video.

Any thoughts?

Thanks so much!

$\endgroup$
2
  • $\begingroup$ Hello! Are you looking for a solution in 3.0 or are you open to using the beta 3.1 ? $\endgroup$
    – Gorgious
    Commented Feb 24, 2022 at 6:50
  • $\begingroup$ @Gorgious 3.1 is okay! What makes the difference between 3.0 and 3.1 for this solution? $\endgroup$ Commented Feb 24, 2022 at 22:32

1 Answer 1

6
$\begingroup$

in 3.1 this works:

enter image description here

i hope you don't mind using the realize instances node...

enter image description here

enter image description here

Explanation try (i have no idea what changed from 3.0 to 3.1 - sorry about that): The index will be "captured" by the capture attribute node from the geometry (group input) which is a cube. So it runs from 0 to 7 (which you could check by plugging in a viewer node). This index will be linked to the output so that we can use that attribute in the shader tree. This attribute will be divided by 8 because the colorramp only accepts/uses values from 0 to 1, so we get a different color for every index. Of course you would have to adapt the colorramp and the division value if you have more/less vertices.

$\endgroup$
9
  • $\begingroup$ Why do you ask if they mind using the realize instances node? $\endgroup$
    – Neil
    Commented Feb 24, 2022 at 16:17
  • 2
    $\begingroup$ because i am not sure whether the OP wants this... $\endgroup$
    – Chris
    Commented Feb 24, 2022 at 16:20
  • 1
    $\begingroup$ Ah ok, I thought that it was some performance issue or something, thanks :) $\endgroup$
    – Neil
    Commented Feb 24, 2022 at 16:51
  • 1
    $\begingroup$ @Chris You've made many wonderful answers on this site, but I do sometimes think an explanation of how and why the answer works, in addition to the pictures, would be great. $\endgroup$ Commented Feb 25, 2022 at 15:03
  • 1
    $\begingroup$ looks like Crantisz already has a solution ;) $\endgroup$
    – Chris
    Commented Jul 29, 2022 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .