For quite a long time Unity was unavailable to the part of users, who didn’t deal with coding like e.g. graphic designers but still wanted to show more in their projects than just standard solutions connected for instance with materials. Everything changed when Unity added a shader graph as a standard engine tool.
Shader graph serves for visual shader scripting – you can create very advanced or simple shaders adapted to your project’s needs while using nodes and cords without the necessity of coding.
The following tutorial shows how to create a shader that allows us to freely change the asset’s color, without the need of generating hundreds of textures or materials.
See how to create a shader step by step
Meet RoboHelper who will assist me with this tutorial:
At the moment RoboHelper has a standard material with a set of textures:
As you can see, the color change is possible but in most cases really useless:
Create a new shader graph
For comparison purposes, I’ll create a friend for RoboHelper – RoboHelper 2
In order to create a new shader graph, do the right-click right on the appropriate folder and choose to Create >> Shader >> PBR Shader (shader graph is only available for unity projects in URP and HDRP rendering pipelines)
First, I’ll be presenting the features of a standard shader:
Next, you have to get rid of the colors from the albedo channel, which can be done via the saturation node in the shader graph.
Alternatively, you can use an already prepared texture:
I will be using the prepared texture, as there is no need to overload the shader with unnecessary calculations.
Afterward, I will be using masks for specific colors.
Those had to be prepared earlier in a graphic or texture mapping software.
The base, discolored texture albedo will be blended with colors (multiply) and I’ll set the new color’s location while using the LERP node and the mask color as alpha.
That needs to be repeated for each mask color:
Then, I’ll add an optional mask in a similar way but this time, I won’t be merging them into one texture.
The next step is to add parameters, which will allow us to add optional details:
Finally, I will add one more mask, this time a universal one that will serve as a logo. In order to use a mask this way, I had to draw up an additional UV map for RoboHelper in a 3D graphic software (blender) beforehand:
This is how the final graph looks like:
Although I only limited myself to colors here, you can obviously use the mask to set other parameters, like e.g. metallic & smoothness. As you can see, an appropriately set up shader gives us unlimited possibilities, without sacrificing quality.