Author Topic: Substance Painter 2.2 Material Layering in Unity- don't get it.  (Read 3412 times)

Followed both tutorials, my version of Substance gave me a Blending Mask, Not Opacity.

The painting of the Fire Hydrant went exactly like the tutorial, looks about the same. No issue there.

Exported to Unity using the (Document Channels + AO + Alpha) like the video.

Installed Plugin for Unity.

1) I have no clue where the materials came from in the 2nd video. Magic possibly? I need those. I was told I already needs those materials loaded into my project. So, where do you get those?

2) What good is it exporting the mask as in the first video?

3) I would make the materials, but I can't get the Albedo texture I need from Substance painter. Exporting as normal with unity Metallic does not work. The mask is just a white blending mask that I can export.

[MapExporter] Nothing could have been exported on the fire_hydrant_Mask stack:
[MapExporter]     The channel Opacity is not available in the fire_hydrant_Mask stack.
[MapExporter]     The channel Roughness mandatory by Glossiness is not available in the fire_hydrant_Mask stack.
So on and so on.

4) Loading my Json file just gives error in Unity. Was hoping it would just magically work.

AlgLayeredMaterialEditor+MaterialLayeringData.Load (System.String jsonPath, System.String targetPath) (at Assets/Allegorithmic/MaterialLayering/Editor/AlgLayeredMaterialEditor.cs:211)
AlgLayeredMaterialEditor.LoadJson (UnityEngine.Material targetMaterial) (at Assets/Allegorithmic/MaterialLayering/Editor/AlgLayeredMaterialEditor.cs:646)

I watched both video's several times, my Fire Hydrant looks great in Substance Painter. I have no clue how to get it into Unity.

Thank you for any help.

The goal of the material layering workflow is to author masks, to blend generic materials together in the shader.
The workflow assume that you have the same materials already set and ready in both Substance Painter and Unity so that you only have to load the mask and the Json and the setup will be automatic.

You can take a look here as well :

I will ask around for the errors on the Unity side however.
Don't forget your log file. It can be exported from the Help menu of the software.
Fabrice Piquet aka Froyok. Product Manager, Technical Artist and Documentation at Adobe.

Thank you very much for the response. I don't think I am explaining the issue well enough.

The "WORKFLOW" part.

You said it assumes I have the same material already set and ready both in Substance painter and then in Unity. Like this clip from the tutorial shows.

That material is cleary from substance painter.

I painted my Fire Hydrant following the tutorial. Here is a picture.

You can see I have the same material red_paint, Steel Rough, Rust Fine and dirt.

My question:
How do you get those materials to export out for Unity?

If I export it as unity metallic I get this.

I understand the materials need to be in Unity, but the materials used in the tutorial came from Substance. I have no idea how to get my materials to export. exporting the mask only does not give me any Albedo texture for the fire hydrant.

Exporting the mask like in the first tutorial only gives me a blending mask for Albedo. I can't make a material out of that or at least get a red Fire Hydrant.

this is what I end up with.

I watched both videos several times as not to miss anything and have no idea what I did wrong.

do I have to paint the fire Hydrant normally, then repaint it? Sorry if I am not catching on here.

Thank you for your time.

You don't need to export the materials as you would normally in painter, it's only the masks you're interested in exporting here. Just find the .sbar files on your computer and drag them in to your project somewhere. When you click on load Json on the material layering shader, it will populate the materials from the .sbar files in to the shader. It will also combine the masks in to one.

However!!! There is a bug with the current version of Painter and 2017.3 Unity. I'm still working on figuring out what exactly the bug is so I can't advise further than that. The error in Unity I get is this:

AlgLayeredMaterialEditor+MaterialLayeringData.Load (System.String jsonPath, System.String targetPath) (at Assets/Allegorithmic/MaterialLayering/Editor/AlgLayeredMaterialEditor.cs:223)
AlgLayeredMaterialEditor.LoadJson (UnityEngine.Material targetMaterial) (at Assets/Allegorithmic/MaterialLayering/Editor/AlgLayeredMaterialEditor.cs:658)
AlgLayeredMaterialEditor.OnInspectorGUI () (at Assets/Allegorithmic/MaterialLayering/Editor/AlgLayeredMaterialEditor.cs:483)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1253)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

I believe it's something to do with how the SimpleJSON plugin parses the masks because for me, it's not finding any. It's a real shame, as this is a very useful shader.

I know the Allegorithmic team are busy with the Unity 2018 plugin but please can someone also have a look at this?

Many thanks

I should add:

As I've added lots of Debug.Log's to the AlgLayeredMaterialEditor.cs file the error message I showed above won't match line numbers. The line that fails is the File.WriteAllBytes from the following section:

Code: [Select]
string filename = targetPath + "/" + textureSet.m_Name + "_masks" + (currentPackedTexture > 0 ? (currentPackedTexture + 1).ToString() : "") + ".png";
                    Utils.Log("Writing packed masks file " + filename);
                    File.WriteAllBytes(filename, packedMasksTexture.EncodeToPNG());

If anyone else wants to fix the error with the Json import when exporting masks from Painter 2018, I did the following:

At the bottom of the Json files created by Substance 2018.1.1 there's a Json node called "texturesets". It should read like this:

Code: [Select]
"texturesets": {
        "YourTxtSetsName": {
"shader": "Main shader",
"stacks": {
            "Mask": {
                "Blending mask": "YourTxtSetsName_Mask_Blending_mask.png"
            "Mask2": {
                "Blending mask": "YourTxtSetsName_Mask2_Blending_mask.png"
            "Mask3": {
                "Blending mask": "YourTxtSetsName_Mask3_Blending_mask.png"

However, in the 2018 version of the Json file that gets exported, the line that specifies the shader and the "stacks" reference is missing. I inserted them manually and the Json loads fine. The SimpleJson plugin is looking for the Stacks KVP, so I'm guessing that's why it fails. This will also fix not being able to reimport the shader settings back in to Painter.

"YourTxtSetsName" in the code snippet above obviously should be changed to whatever you specified your texture sets as in Painter.

It does mean manual intervention is needed for now for any new Json file you create but at least it's fixable.

Hope this helps someone else.