Note: This guide was written for Unity 2019.2 using LWRP v. 6.9.1.
Say you want to layer some effect on top of Unity’s PBR shading using Shader Graph. You may soon find yourself in a tight spot. In the Lightweight Render Pipeline there are two Master Nodes available in Shader Graph: PBR and unlit. These Master Nodes are the last nodes of graph; nothing can come after. So you are left with two options: plug your effects into the Emission channel of the PBR node and deal with those limitations, or do the lighting calculations yourself and plug the output into the Color channel of the unlit node. Going the unlit route gives more control, but is a bit more daunting. However, there is a quick fix that will allow us to create an intermediate PBR node.
If you poke around in Packages/Lightweight RP/ShaderLibrary/Lighting.hlsl, you should find some useful functions to achieve lighting using the same lighting models that Unity does. Two wins: reusing existing code and consistent lighting style. The highest level function in there (which we will be using for our custom PBR node) is called LightweightFragmentPBR.
So, simply create a new hlsl file and paste the following in:
Then create a sub-graph and set up your custom node like so, using the source .hlsl file you created.
This will help with reusability, because you can grab the sub-graph instead of setting up the custom node each time. Now you can create an intermediate PBR node in any shader graph by selecting, New Node>Sub Graph>LightweightPBR. However, note that it should really only be used with unlit master nodes, as a PBR master would be redundant and would not give the desired effect.
Then you just have to hook it up to meet your needs.