Your own Standard shader - TUTORIAL (Patreon)
Content
Standard light model is one of the common shader light models. Basically, it's what the Unity Standard shader uses for physically based rendering (PBR).
So, what is it actually? This light model is the best for physically correct visualization of most of the objects. Want to render something photorealistic? Standard shader is exactly for this purpose. It can use "Albedo", "Normal", "Metallic", "Smoothness", "Ambient Occlusion" and even a few more maps. Maps are basically textures sometimes mixed with some color.
So, let's try to make our own Standard shader implementation using Amplify Shader Editor! Why do we need it? It is really necessarily to know how the standard light model works, cuz we'll make a lot of shaders based on this model in future.
First of all let's add a "Texture Sample" node (Key "T") and rename it to "Albedo".
NOTE: To use hotkeys, you need to press the hotkey and click at the same time.
It is your first and main shader texture. You can attach it to your main shader node input to check out what it does:
Then, let's create a material based on our shader and add a simple texture to Albedo slot there:
It works! Wow! But it doesn't have a color toning ability such as in Unity Standard Shader, so lets add it simply by multiplying (Key "M") your Albedo by a Color node (Key "5").
NOTE: To make any of input nodes configurable and visible in material properties, set it's type to "Property" in node parameters.
Our shader will have lots of maps, so it will be nice to use local vars to prevent a big mess in future. "Register Local Var" node registers a variable you input in it with a specified name. "Get Local Var" node just gets it in another place of your workspace.
Now, let's add the other nodes!
Normal map Texture Sample node should configured this way:
Default texture: Bump
Unpack Normal Map: Yes
It should also have an input scale float (Key "1") value:
Metallic and Smoothness are usually uses the same map but a different channels. Red (R) channel for Metallic and Alpha (A) for Smoothness. Yes, you can use a one texture to represent up to 4 channels! It is super useful for compact memory usage.
So, let's add a Metallic & Smoothness map node with some floats to control it's power by simply multiplying:
Emission and Ambient Occlusion maps are not something special too. But take a note that Ambient Occlusion should use Green (G) channel and a Lerp node (Key "L") instead of a multiply node. Lerp node is used to lerp colors between default for Ambient Occlusion white and your Ambient Occlusion map's color. Just specify a value "1" in your A Lerp input:
Emission setting should be similar to Albedo:
Now it's time to specify the same UV settings for all of your maps. If we want it to be the same as in Unity Standard shader, we should grab it from Albedo Texture Sample node.
Just add a Texture Coordinates node (Key "U") and target it's "Reference" property to "Albedo" map. Then register it as a local variable and use it for every map we have.
If you want it to be a transparent shader, just switch a Blend Mode to Transparent in your main shader node options and connect your Alpha Albedo channel to Opacity input. You should also probably mix it with your Albedo Color Alpha (A) channel.
The result should looks like this:
Actually, our own Standard shader is ready. But to match it with Unity Standard shader properties naming, lets unlock manual property name setting in each of our property nodes:
Then, rename it all such as I specified here:
Albedo map: _MainTex
Albedo color: _Color
Normal map: _BumpMap
Normal power: _BumpScale
Emission map: _EmissionMap
Emission color: _EmissionColor (Also specify the HDR attribute for this one)
Metallic & Smoothness maps: _MetallicGlossMap
Smoothness power: _Glossiness
Metallic power: _Metallic (Also specify the Gamma attribute for this one)
Ambient Occlusion map: _OcclusionMap
Ambient Occlusion power: _OcclusionStrength
Now our shader parameters can easily migrate from Unity Standard shader to ours and no need to be reconfigured. So, it's done for now!
Thank you for reading, don't be shy to become a patron and download all the source files from my tutorials.