How to randomize colors on instanced objects without realizing them?

Hi!

When working with instanced objects, I’d like to assign them random color from a certain range. But maybe I don’t see what’s in front of me anymore or it just got a bit more complicated in my case.

Here’s the idea:

  • each instance has it’s own color
  • no “realize instance” node
  • randomization of color has to be influenced from within geometry nodes
  • these color adjustments should stay even after making instances real (eg. some darker, some brighter)

Is this possible, with the requirements I stated above? I was thinking about it for a while, but very scarcely worked with materials, so I hanging out dry here…

To explain more in detail why:

I’m creating new maps into a game. By looking at the map metadata file, I realised (pun intended) I could potentially create variety of grass instances via GN, each with their own world location, rotation, color and other attributes for later export via Python. Rather than painting them via dedicated editor on a large scale surface manually, which is a very tedious task.

bl_arts_ran_mats.blend (2.0 MB)

Any advice will be appreciated!

see this thread: :slight_smile: B3.2 geonodes instances color variation problem - #4 by AlphaChannel

1 Like

Thank you!

I also tried to print color sockets, but couldn’t figure out how. I was trying to find an option such as

.outputs[0].colour or .outputs[0].value

but the closet to that was only “default_value”, which is not desirable, as I want to grab those randomized color values. I’ve been looking, but only got what I didn’t need or errors instead.

Could you tell me what am I doing wrong?

import bpy
print("NEW")

# Define the input node name
input_node_name = "VALTORGB"

# Color value to set (R, G, B)
color_value = (0.5, 0.0815209, 0.196314,1)
# Iterate through selected objects
for ob in bpy.context.selected_objects:
    # Check if the object has an active material
    
    if ob.active_material:
        material = ob.active_material
        
        # Check if the material has a node tree
        if material.node_tree:
            node_tree = material.node_tree
            
            # Find the specified input node
            for node in node_tree.nodes: 
                if node.type == input_node_name: 
                    print("value is ",node.outputs[0])`

Randomize colors could be done like this -

1 Like

@Benny_G 's solution is how I’ve been doing it within geometry node instances. For example:

I did the same with the “fur” color, running that from random into a 4 color ramp. Both materials were assigned on the original object/cat head prior to instancing it.

Not sure how that would be tackled as a script, however.

1 Like

Maybe you could store the attribute to the realized geometry with geometrynodes with this addon

I used a slightly different approach, to random colors…

You should be able to drive the W-value of the Whitenoise from within GN…

Is this what you want?

@Chanfiroly @RSEhlers

Both solutions are doing what I want to see, but can those individual instances retain their respective colours when made real?

I’d like to made them real, so I can get their color attribute later via Python per each unit individually. But I couldn’t make that to work.

The only alternative that worked for me so far was to use collection with several duplicates, each with a different material. That’s not a very elegant and flexible solution when working with procedural terrain though.

Ah sorry I misread your post, I understand now.

You need to assign a Color attribute - then realize - and apply geometrynodes - then you can use the color Attribute -

1 Like

Well, if my goal was to have one single mesh, then yes.

But i’m trying to get large amount of distributed grass instances as separated objects, each with it’s own colour variation.

I don’t want to realize them. I need to make them real.

Let’s forget about color, for a moment.

How are you making a geometry node instance real, without realizing the instance?

1 Like

I’m creating new maps into a game. By looking at the map metadata file, I realised (pun intended) I could potentially create variety of grass instances via GN, each with their own world location, rotation, color and other attributes for later export via Python. Rather than painting them via dedicated editor on a large scale surface manually, which is a very tedious task.