1

I have a point line and am instancing this Parasol object along the points. I only want to alter the specific colored portion of the object so that each instance is a different color in relationship to its index number, so that each instanced object would be the next color of the rainbow in accordance with the color ramp. I'm having trouble knowing if I should realize instances, because all of the model's textures change when I am only wanting to affect a certain texture in the model.

I thought I could do this by storing the object index as a Stored Attribute, but every instance is the same color no matter what I do. my geo nodes setup my shading setup the instanced objects

Connor m
  • 11
  • 2

1 Answers1

3

ColorRamp node operates in a range 0-1 ... using your setup should result at least with one instance blue (because of index number zero) and the rest of instances red (because their index number is 1, 2, 3, ...)

Note: Since all your instances are blue (=0) you probably need to add Realize Instances node after Store Named Attribute node (that is not needed for Blender 3.41 as mentioned in Markus comment).


To apply ColorRamp gradient across all instances you have to shrink all the index values down into 0-1 range. Like in this example - the first instance with index 0 should give the value 0 and the last instance with index number 35 should give the value 1.
Note: The grid contains 36 instances, but since the numbering starts with 0 and not 1, the highest index number is 35.

There are several ways to do that ... you can just simply add a Map Range node into your shader node tree with From Min set in this example to 35:

... but it is more efficient to scale the range with Geometry Nodes. There can be range scaled into 0-1 automatically for a given number of instance points. The math here: Index node values Divided by the number of instances taken from Domain Size > Instances. And because index list operates in the range 0-35 and instances 1-36 you have to Subtract the list by 1:

Alternatively, in case your instance object contains a single mesh (island) or you connect all separate parts of the mesh by edge, you can use the Mesh Island node https://imgur.com/0UUG3uf

Thanks @MarkusvonBroady for corrections in the comments ... works for Eevee now too.

quellenform
  • 35,177
  • 10
  • 50
  • 133
vklidu
  • 36,165
  • 1
  • 61
  • 135
  • 1
    You could divide in geonodes to only use a single attribute in the shading, maybe this could fix the problem in Eevee (maybe it doesn't support integer or larger than $1$ attribute in your version? And as said under the question, you don't need to realize in B3.4+ – Markus von Broady Sep 30 '23 at 19:31
  • 1
    @MarkusvonBroady it seems to be 100% correct :) My issue was Integer ... switch to Float works. Edited. Thanks a lot :) – vklidu Oct 01 '23 at 05:53
  • 1
    Be careful with mesh islands, if your instance is Suzanne for example… :) – Markus von Broady Oct 01 '23 at 12:00
  • 1
    @MarkusvonBroady ... correct again :) +1 – vklidu Oct 01 '23 at 12:05