PBR Shader Graph
A Powerful tool that can help build amazing looking Shaders with visual aid and without the hassle of learning shader code syntax.
I want to explain what the Shader Graph is, how it works and how to use it, as well as show some examples, so let’s get right into it.
Part 1: Unity
This is probably the least interesting part of it all; Unity is a pretty popular and versatile Game Engine with a lot of great development tools that any one can use for free. That said, I currently favor using Unity over other Engines like Unreal Engine 4, but this post would apply just the same to UE4, with the only difference being the minutia of how the node editor works exactly and some kinks and quirks.
But just in case it’s important to someone:
The similar editor in UE4 is called “Material Editor” and is linked in the Sources list below.
Back to Unity though, for the most part it used a pretty straight forward and standard approach to shading, shaders are written in either ShaderLab for a very simple approach (but friendlier to get into) or in Cg/HLSL, Cg being a shader language developed by NVidia based on C while HLSL is the High Level Shading Language created by Microsoft used by DirectX.
And to be quite honest, shader syntax can be a bit annoying to get into and for me personally: just aren’t that fun to code. Luckily Unity released their graphical editor called “PBR Shader Graph” in Unity 2019.1.
Part 2: PBR
PBR stands for Physically Based Rendering is a combination of techniques that can be used to accurately try to render Materials in Games (or other 3D software) akin to the realworld where lighting, specularity, smoothness and other factors are taken into account.
PBR is becoming more and more relevant these days with games like Star Citizen, Path of Exile 2 and most of the AAA titles adopting it to reach more realistic and/or sophisticated visuals. But it’s not without flaws: It vastly increases the work digital artists have to do for it to work and it impacts performance as well. This is due to the number of additional factors a PBR Material takes into account, which is part of the reason why – with all the improvements on software and hardware – most AAA titles are getting more expensive to make and have quite steep hardware requirements. Both Microsoft and Sony are pretty much following this trend, hence the pretty beefy hardware in their upcoming consoles.
Part 3: Shader
For those unacquainted with the way games are rendered; here’s the quick summary:
A Shader is a set of instructions or calculations that the CPU/GPU can use to determine exactly the look of any pixel in a given frame.
And this depends on the Material of the object the pixel is representing, a wall will have a vastly different Shader compared to water and water will have a completely different Shader compared to things like UI elements.
Depending on the Material this can take various factors into account that we can know of a pixel like:
- Position of that pixel in the world
- Normal direction of the face that the pixel is on
- Depth of the pixel (distance to the camera)
- Color/Texture of the face that the pixel is on
This is also used to either work with or outside other effects like Icons that should not be affected by the in-game fog or water that is transparent, moves, has an animated normal map and darkens anything below.
Part 4: Graph
A “Graph” is really just refering to a Node based graphical visualization. A Node either generates or manipulates values for a desired output, this can be chained together (as seen above) to create sophisticated ways how things are rendered.
And it’s really important to always remember that the Graph is like an instruction set that is executed for each pixel that is rendered.
Sidenote: The example above might look complex, but some shaders are made up of hundreds of these Nodes, easily dwarving my little basic graphic.
That’s it for this time, but I still have more on this topic, next month I will be sharing a guide from A to Z for Unity’s PBR Shader Graph as well as some more interesting information about the topic.
Until then, I can only encourage those enthusiastic about the topic to check out the resources linked below.
- Writing Shaders by Unity Technologies
- Material Editor Reference by Epic Games
- HLSL by Microsoft
- Unity Roadmap Archive – by Unity Technologies
- Physically Based Rendering – on Wikipedia
- PBR/Theory – by Joey de Vries / LearnOpenGL
Also, here are some more resources on the aforementioned topics: