How to quick render Material-Masks only

Hi

I wanna quick render Material-Masks (example see here, first post. Unfortunately the Script there does not work anymore) only.
How can I do that without rendering the complete Scene again ?
I need the Masks later in Photoshop.

Kind regards
Alain

Hi Alain,

you must render the scene again, but only the mask (with lower samples).


Hi Dito

Thanks for your answer.

That also means that I have to reassign all (Emission-)Materials again ?
If yes, that’s to time consuming, isn’t there a Script for that ?

I’m not being Dito, but…

You see it on the Screenshot.
You override all Materials, no reassign for the other Materials.

Make some Object (e.g. a Plane or only a Vertice).
Make the Random Material for it.
In the Render Layer Tab go to Material and insert the Random Material.
All other materials will overwritten.

Give it lower samples then your normal scene. (Below the Materials)

Vertex (english), not vertice (latin, italian). The material could be added for any of the existing objects’ material stack for the shown setup. First material gets assigned to everything, and next ones need to be assigned to mesh faces but not in this case, because material override will do it.

It doesn’t answer the question though. The material setup and material override only works as object id mask, but the OP is asking for material masks in the thread title.


The thing with id masks is that they’re aliased. The pixel value is the ID. A color picker would get the exact boundary of those.

Can’t use index passes and make them anti-aliased in the compositor because that will create problems with the boundaries (1). Render engine does anti-aliasing, but that also means new colors on the anti-aliased parts (2), which means that a color picker won’t be able to pick the exact mix in all cases.

I have a startup file where there are:
an override “mask” material
a “mask” renderlayer, set with the override material and 256 samples

now, the mask material is set like this


the point is that you’ll have to set each individual object to have its own index number

0 = black
1 = white
(in case of monochrome masks just use 0 or 1)

2 = red
3 = green
4 = blue
so that in a single image you can store three different masks

as you can see, you can also use material index instead of object index.

Hope this is useful

Which will return the index of the override material, giving all materials the same color when used as override. How are you getting a different color for each material?

Not a big problem. Could for example assign them with


import bpy

for i,o in enumerate(bpy.context.selected_objects):
    o.pass_index = i

It’s for selected objects in case there are multiple types. Instances (procedural duplication, particle system, linked libraries) would probably need a different solution.

Or for materials


import bpy

for i,m in enumerate(bpy.data.materials):
    m.pass_index = i

And the number of objects or materials needed for normalizing the indices to 0-1 range from the header, or from outliner data blocks view, or with


len(C.selected_objects)
len(D.materials)

In python console

oh, I forgot. I use this node as a pass-trough inside my main UberShader node, so pretty much every object in my scene has this node just before the output. So that I can make material masks without the override feature. I just connect the emission node into Shader output when I need it.

Not a big problem. Could for example assign them with


import bpy

for i,o in enumerate(bpy.context.selected_objects):
    o.pass_index = i
 [...]

the point here is that I can manually choose what mask color each object will have

And the number of objects or materials needed for normalizing the indices to 0-1 range from the header, or from outliner data blocks view, or with


len(C.selected_objects)
len(D.materials)

In python console

the indices are 5 and just 5 for a reason: black/white or 3 RGB channels. I can output a single grayscale mask or three grayscale in a single RGB file. I mostly pass them for postpro in photoshop, and they are intended to be used as real selection channels, not for “magic wand” selection.
That’s the use i do of this.

With this solution I have to switch every Material by hand again ?

Would need to use python to change the materials, or check https://www.blendermarket.com/products/idmapper

Apart from those, the only thing I can think of is to make a copy of the object(s), apply modifiers, separate by material, and use data transfer modifier on them if needed. That way the random color material override can be used since they’re separate objects, object/material. Search for separate in object mode if done for multiple objects.

it means putting this nodegroup in every material? yes.
it means tweaking every material? no. You just tweak once the nodegroup and every instance of it is updated.
Using this kind of passthrough nodes (i have several others) is a before-head job, but gives a lot of benefits for this kind of tasks