I have a 3d small garden with 15 plants. Each plant have leaf objects. Formally they are just a leaf objects with different XYZ location/rotation/scale. Take a look

I want to get something similar to this image:

enter image description here

I need to make an RGB mask of my garden? How do I make it?

I'm thinking of creating a new materials and give them random coloring and then apply materials on my leaf objects, that would work too I suppose, but I believe there should be an easier and better way.

Here's my script:

for obj in [o for o in source_collection.objects if o.type == 'MESH']:
       for i in range(1):
           for obj in [o for o in source_collection.objects if o.type == 'MESH']:
               # get a copy of the object
               new_obj = duplicate( obj, destination_collection, False )
               # ** Make your random transforms here ** 
               RGBMask = bpy.data.materials.new("RGBMask")
               bpy.data.materials["RGBMask"].diffuse_color = random(), random(), random(), random() 
               rotateX = round(uniform(-20,20), 2)
               rotateY = round(uniform(10,50), 2)
               rotateZ = randint(-760,760)
               scaleX = round(uniform(0.3,1), 2)
               scaleY = round(uniform(0.3,1), 2)
               scaleZ = round(uniform(0.3,1), 2)
               new_obj.scale = ( scaleX, scaleY, scaleZ )
               new_obj.rotation_euler = (radians(rotateX),radians(rotateY),radians(rotateZ))

It creates new material called RGBMask, but applies it for all of my objects, but I need to have each leaf have it's own color. I'm new to python and blender, so any help is highly appreciated

  • $\begingroup$ I believe cryptomatte is what you want: youtube.com/watch?v=Ml1Kic4VopA $\endgroup$
    – Robert Gützkow
    Aug 9 '19 at 12:03
  • $\begingroup$ @rjg it's very close to what I want, figuring out now how to use it. Thanks for the tip!!!! $\endgroup$
    – cxnt
    Aug 9 '19 at 12:42
  • $\begingroup$ You can use the vision_blender add-on for this. It crates segmentations masks for you when you render an image. $\endgroup$ Sep 29 '20 at 7:58

You can try with this solution: Create a segmentation picture with each object class rendered in different color ?. It worked for me.

Moreover, if you want sharp edges you can set render properties -> film -> filter size for eevee to 0.00.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.