PBR Shaders Explained (Patreon)
Content
Hey! I decided to talk more about Physically Based Rendering (PBR). In a previous tutorial I already told you about it, but for some people who are new at computer graphics, it was something incomplete. With Standard unity PBR materials you can make a lot of beautiful stuff. This materials requires some texture maps such as: "Albedo", "Normal", "Metallic", "Smoothness", "Ambient Occlusion" and sometimes even more maps.
NOTE: I'll be talking about a Standard Metallic Unity workflow, not Specular!
What is Albedo?
RGB channels of Albedo textures represents the color of object's material. Not a solid color, basically it's just a visual part of your material without any shadows, gloss and other stuff. Just a color texture.
Alpha channel usually represents transparency. If your object is opaque, the alpha channel usually doesn't contains something useful. But! You can store a Smoothness map in it. We'll talk about is very soon.
Talking about a physical explanation, Albedo map describes how much light absorbs by the object and how much light reflects.
Of course, Albedo can be colored, and in this case it describes how much light reflects and absorbs in all the visible color spectre.
What is Normal map?
What a strange magic blue texture that makes all objects looks better! How does it works? Actually, it's simple.
Normal map is used to make objects look like they are super detailed, without making it super high poly. It describes object's curvature, micro details like scratches, grooves, etc. Using normal maps, PBR material makes low poly object reflect light like it's pretty much high poly, draw shadows where it is even no geometry for this shadows. Basically, makes low-poly object looks like it's super detailed high-poly.
But how it actually works? To have an information about your object's curvature, your graphics card needs it's surface normals. Normals are perpendiculars to object's surface. Basically, 3D vectors.
A picture below, shows each polygon's normals of my lifebuoy model as an example. Normal maps contains the exact same information, but for each pixel of your object's texture, which describes the object's curvature much more precisely.
Each pixel of a texture have at least 3 channels, R,G,B. And we need just 3 values to describe any 3D vector. So, one pixel is enough to describe a normal vector! Isn't it cool?
R channel describes normal vector's horizontal direction, G - vertical and B - it's height.
Interesting fact:
Just because there is usually more regions with normals, directed almost straight up, the map looks blue. Lets's try to describe a vertical vector in an RGB color space:
R: 128 (middle vector position)
G: 128 (middle vector position)
B: 255 (highest vector position)
And let's see how the RGB (128, 128, 255) color looks like:
That's it, our blue-normal color ;3
By the way, normal map vectors are relative to real vertex normals stored in your object's geometry.
That's another explanation how it works:
To make a normal map from our high-poly surface for our low-poly surface, we are just projecting our high-poly normals to our low-poly geometry and calculating a relative normal map.
What is Metallic and Smoothness?
It's very simple. Metallic map represents the regions of your objects which are metal or non-metal. And Smoothness represents the regions which are matte or glossy.
Unity Standard shader uses one texture for both Metallic and Smoothness maps by default. Metallic map is a grayscale texture map stored in Red channel. Smoothness is also a grayscale map, but stored in Alpha channel.
Brighter the Metallic map - more metal-like your object will be. Brighter the Smoothness map - more glossy your object will be.
A quick material values for explanation:
Matte rubber - Smoothness: 0.1 | Metallic: 0
Super glossy plastic - Smoothness: 1 | Metallic: 0
Mirror - Smoothness: 1 | Metallic: 1
Brushed steel - Smoothness: 0.6 | Metallic: 1
Clear glass - Smoothness: 1 | Metallic: 0
Dirty matte glass - Smoothness: 0.7 | Metallic: 0
And a little lifehack: If your object is opaque and not metal at all, there could be a good reason to save your memory and store the Smoothness map in your Albedo's alpha! Then just choose an option "Smoothness Source: Albedo Alpha" in your Standard material.
What is Ambient Occlusion?
This is not a very common map, but sometimes it makes a really good visual effect. Basically it creates something like more shaded areas of your material. Usually, it's geometry corners, grooves and some other stuff.
This sparrow below uses Ambient Occlusion (AO) map in it's material. (ON and OFF shown on the both images) It makes the inside of its mouth looks shadowed.
But a question comes... Why don't just make this darker areas a part of Albedo? Yes, you can do this to save some memory and get a similar effect, but there is quite a difference between Albedo and AO.
Albedo color can be affected by direct and indirect light. And AO describes how it can be affected by Indirect light (Light of the light probes, reflection probes, baked indirect light and ambient light). But the object will still be good lit by a direct light.
It makes a little bit more correct visualization of your object.
Ambient Occlusion is a grayscale map and uses a G texture channel. So, you can easily combine it with your Metallic and Smoothness map to save some memory. This setup will look like this:
R - Metallic
G - Ambient Occlusion
B - Unused
A - Smoothness
What is Emission map?
This is an RGB map, that describes the regions of your object, which emits light. Basically, glowing regions. It can be monitor screens, light bulbs, any other stuff. If your object don't needs to be affected by any light, you can use emission map to make it looks unlit and full-bright. But for this, I'll recommend to use an unlit shader instead of Standard PBR. The black color of the map doesn't emit any light.
PS: Some post-processing shaders can also create a glowing effect for your emission map regions.
There are still more PBR maps to talk about, like Displacement map, Subsurface Scattering map, Refraction map, and other. But we'll talk about all of them later.
More about the Standard Unity PBR setup you can read in Unity official docs.