Custom and toon lit master nodes
Warning
With Unity 2019.2, Unity released its own custom lighting example. At the time of writing (july 2019), their solution seems better than mine, because you can more easily pass parameters and you can do part of it in ShaderGraph itself. I’ll let people test their solution a bit, and if it’s stable I’ll probably deprecate this feature in ShaderGraph Essentials.
Note that in the Demo_URP/Shaders folder, the SGE_ToonLit shader is a good demonstration of this feature. If you’re interested in coding your own custom lighting, I will assume you know a bit of HLSL. The typical use case for this feature would be if you had a custom lighting function in Unity shaders and you would like to port it to ShaderGraph.
Quick guide
- In project view, right clic Create -> Shaders -> SGE Custom Lit Graph.
- This will create a graph, which already contains a custom lighting master node and another node.
- The pre-existing node is a Custom Function Node that points to a shader. You want to duplicate it and have the Custom Function Node points to your new shader. Then open the shader.
- It contains a bunch of helpful comments, and 3 functions:
- SGE_DiffuseLightingCustom which you can change, it’s the diffuse lighting function. Just don’t change the name or parameters, or it won’t work.
- SGE_SpecularLightingCustom which you can change, it’s the specular lighting function. Just don’t change the name or parameters, or it won’t work.
- Passthrough_float which you shouldn’t change. It’s just a dummy because Unity requires a function to be integrated in the graph, otherwise it’s optimized out.
Toon lighting
The toon lighting implemented in this lighting is simply a showcase of the custom lighting function. Feel free to use it how you want, it’s definitely performant and production-ready! However you might want to change it to your tastes; maybe add a texture ramp, remove the rim light ...etc, which is totally doable if you’re familiar with HLSL.
Feel free to contact me if you would like this shader to support additionnal feature!