If I create a new shader, PBR graph with just the PBR master node, and compile and show code of shader it’s over 227,000 lines of code long. The “standard” shader when opened in visual studio is only 338 lines long.
Why is this? I’ve never messed with shaders, or shader graphs at all. I have been using standard mobile shaders, and some from asset store, but have wanted to make my own. After converting to the Universal RP and shader graph to make my own visually, as I have no experience coding my own, I’m wondering if it was a mistake.
There would be a few main reasons for this:
1 - Different platforms use different graphics APIs, and not all functions are compatible with differing hardware. As such, it is often useful to compile many shader variants - copies of the shader with small changes which can be changed based on platform/performance needs.
2 - To limit code duplication during development, we also use includes when writing shaders that allow common code to be written once but used throughout different parts of a shader. As shader graph generates the whole shader, this step doesn’t really make much of a difference. Not to mention that entire libraries would often be included for functionality, but I believe shader graph generates functions when they are used rather than using includes.
3 - I’m guessing the standard shader you are referring to is a surface shader - another level of abstraction Unity created to make it easier to create custom shaders by breaking them down into simple surface and lighting functions. Surface shaders compile into much bigger shaders with lots of hidden code and variants that would otherwise be a pain to write manually.
4 - In order for shader graph to work and be flexible for customisation, shaders would need to be broken down into many small parts and separated, whereas when writing a shader by hand we would intentionally be trying to keep size to a functional minimum.