Get our free workflow cheatsheet!

Join our newsletter and get updates of our news and content as well as our 3D modelling workflow cheat sheet.

Erik Selin
Erik Selin

3D artist & all that other stuff

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on reddit
Reddit

How to use cryptomatte for masking in Blender

Cryptomatte is a new feature in Blender that will allow us to create masks based on materials, objects and even groups of objects. It is the kind of function that you never thought you needed but once you have started to use it, you can not live without. Considering how advanced masks you can make with cryptomatte it is a very simple workflow. Let us jump into what it is and follow up with how we can use it in Blender, some things to think about and possibilities.

Cryptomatte is used to create masks based on objects or materials. It can create very accurate masks with support for anti-aliasing, depth of field and motion blur. It consists of two parts, a compositing node and passes. Enable the passes object, material, and asset in the passes section found in the view layer tab in the properties panel under the cryptomatte subsection. Now you can start playing with the cryptomatte node in the compositing nodes.

What is cryptomatte?

Cryptomatte is a post-processing tool that enables us to mask out separate materials or objects. We can use it together with the compositor to have a very fast workflow where we make changes to objects and materials instead of re-render with new settings when we discover a mistake.

Currently, cryptomatte can only be used with cycles render engine. Before cryptomatte we had, and we still do have object index and material index among the render passes. But this needs to be set up on a per object or per material basis. With cryptomatte, all objects and materials can be set up automatically and it will also support depth of field, motion blur and anti-aliasing on the masks it creates. We can then just color pick the masks that we want in the compositor using the new cryptomatte node.

The reason that cryptomatte is in Blender is thanks to a movie project called Next Gen. Next Gen is available on Netflix and it was made almost exclusively with Blender. I think that is awesome! A technology like this can come to benefit the whole Blender community from one such project and I hope for more such projects in the future. Let’s look at how cryptomatte really works.

What settings do we have for cryptomatte?

Currently, it’s only available in cycles and by default, we are in the Eevee render engine. Therefore, go to the render settings tab in the properties panel and change your render engine to cycles. Now we can go to the view layer tab and bring down the section called passes. We will find a subsection called cryptomatte. You will see that we have access to object, material, and assets this worked like regular passes and we can just enable the cryptomatte that we want. The object and materials will do what you think and help you mask out specific objects and materials. The asset will mask out objects that are parented to the same object. Making us able to Mask off groups of objects much quicker.

settings in the properties panel for cryptomatte

We also have a level and an accurate mode setting. According to the Blender manual, the level settings will dictate how many materials behind each other that can be detected on a per pixel basis. Maybe we have a particle system with a lot of different object and materials. In these cases, this can be useful.

Accurate mode is only available when rendering with CPU. If you find yourself with an inaccurate mask, such as a line around your mask when you use it or another glitch. Try accurate mode. For me though, I have found it more efficient to try to solve the problem some other way than cryptomatte since CPU rendering takes so much longer. But you may find a use for it if you are ok with rendering on the CPU.

For me, in my everyday use, I mostly stick to the material and object pass and I am good for 95% of the way if not more with those 2 buttons alone. For demonstration purposes though we will set all three buttons and go through what they each do. With these three buttons pressed, we can now render our scene and once done, move over to the compositor.

How to set up the compositor for cryptomatte?

Press “use nodes” to enable the compositor for our render result. Enable the backdrop as well. We will use the eyedropper tool from the cryptomatte node to mask out materials and objects from the backdrop. More on this later.

check use nodes and enable backdrop, also switch from alpha and color to just color

To make the backdrop show up, we first need to add a viewer node. Press shift+a and choose search. Type “viewer” in the search bar and hit enter. Using the search option once you know the names of the most useful nodes is far more efficient than looking through the menu.

connect the view layer node to the viewer node instead of the composit node

Connect the image output from the render layer node to the viewer instead of the composite node.

I also had to toggle the view between “alpha and color” and just “color” in the header bar before my backdrop would update.

To navigate the backdrop you will need to remember the V key and the alt key as well as the middle mouse button. Zoom out with the V key, zoom in with alt plus V and pan the image around with alt and middle mouse button while moving the mouse. Personally, I usually set the image somewhere in the lower right corner.

How to set up the nodes for cryptomatte?

Now we will manipulate some more nodes. We will start by enabling the node wrangler add-on which is included with Blender by default. Just go to the edit menu and find preferences. Within preferences, there is an add-on section. Here you can search for the node wrangler add-on. Tick the checkbox next to it in order to enable it.

Now you can hold ctrl+shift and left click on any node to cycle through its output and see it in the backdrop. Do this for the renderer layer node and once you come to the crypto outputs you will notice That these outputs have pretty odd looking outputs.

The first three are called cryptoobject00, 02 and 04. Next comes three outputs for cryptomaterial with the same ending numbers as well as cryptoAsset. Each set of cryptomatte outputs will need to be piped to a cryptomatte node.

You can think of the cryptomatte node as an extension to the render layer node. Hit “shift+a” for the add nodes menu. Here we will find that we have a cryptomatte node in the matte section, or just use the search.

The cryptomatte node takes four outputs as inputs. It needs the image output from the render layer node as well as one full set of crypto outputs either from object, material or assets. This is an example using the object outputs.

connect the three cryptomatte outputs to the inputs of the cryptomatte node as well as the image output. Use multiple cryptomatte nodes for each mask and for each type of mask

To use the cryptomatte node cycle to the “pick” output using the node wrangler add-on so that it is piped to the viewer node. This will make our backdrop look separated into multiple flat colors. We can use the eyedropper tool from the cryptomatte node and pick any color of the backdrop in order to add that to our mask.

We can add multiple parts to the mask by just continue clicking on those areas. You will see that a string of numbers will be added to the cryptomatte node. This represents the color that we pick. If we are viewing any other output than the “pick” output from the cryptomatte node then we won’t be able to use the eyedroppers to add or remove. This is because we will pick from other colors and therefore not create a correct mask or remove from the same mask.

Now cycle through the cryptomatte outputs again until you hit the matte output. This will show you a black and white mask representing your picks. We can now use this to make adjustments to these areas of the image.

The image output of the cryptomatte node is supposed to show the full color image with the mask applied as alpha. However, in my current build of Blender 2.80, I cannot use the alpha for the backdrop to show you. This is most likely a resolved bug when you are reading this. You will just have to trust me I guess^^

That is basically all there is to the cryptomatte node. From here you can use the matte output as a mask to separate out and make adjustments to specific areas of your image without having to spend to much time masking out areas by hand our having to always remember to use the material and object index on every project.

If you find yourself using cryptomatte a lot I would suggest that you enable the passes that you find yourself using and save it to the startup file. This way you will not find yourself without cryptomatte after hours of rendering your latest creation.

Example node setup

Below is the simplest possible example where I add some orange color variation to the grass in order to create some variation. I then mix it with the original image. Keep in mind when using particle systems with cryptomatte that all the distributions of the same object will have the same material and be the same object, so we can’t separate different instance of the same object. For that, we will need a hard duplicate done with “shift+d”.

use the mask from the cryptomatte node into the factor of a mix node to blend between the original image and a flat color
Before cryptomatte setup
After cryptomatte setup

Some things to watch out for and final thoughts

Note that if you are using the material cryptomatte you will have to separate your objects into appropriate materials. Sometimes I see workflows, typically with low poly modeling that involves an image made like a color palette, then in order to change “material” for an object, the UV island for that object is just moved to a different part of the UV Map to change the color. If you plan on using cryptomatte you will soon realize that this is not the same as changing the material.

Another little bug I found at this time is that if you switch to Eevee from cycles, your cryptomatte outputs will be hidden from the render layers node. Just keep that in mind if your outputs suddenly disappear after a render engine switch. Nothing is lost, you just need to switch back to cycles.

I am very glad that cryptomatte has made its way into Blender. It is one of those functions I didn’t know I missed but now when it is available I use it all the time to make smaller adjustments and tweaks.

I hope you found this article useful. If you did, consider joining the newsletter below to get a heads-up from time to time when new content is released.

Get our free workflow cheatsheet!

Join our newsletter and get updates of our news and content as well as our 3D modelling workflow cheat sheet.

More to explore

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.