Writing Shader Code for the Universal RP


A lot of shader code tutorials you’ll see online are written for Unity’s built-in pipeline and won’t really work in the Universal Render Pipeline – They’ll either produce magenta errors or at least won’t be compatible with the SRP Batcher.

Shader graph is an amazing tool which I use a lot. I find it much easier and quicker to write shaders using it. Having previews can really help visualise what the shader is actually doing but I also just like that I don’t have to remember the very specific code syntax and function names. However there are some things which aren’t available in shadergraph just yet – such as proper support for UI shaders, access to all 8 UV channels, interpolating custom data between the vertex and fragment stages, tessellation, etc. All of these are on the shadergraph roadmap but it may be a while before we get to see them, and of course some people might just prefer writing code over node-based editors.

I’ve tried to write this in a way that works as an introduction to Universal RP shader code for complete beginners, but be aware it may get difficult to read (especially on the PBR Lighting page), if you aren’t that familiar with HLSL code. If you have no idea what a shader even is, you’ll probably want to look over some other tutorials first.

If you are already experienced with shader code from the built-in pipeline you’ll want to skip over a lot of stuff here, but I’m putting all the main differences in cyan text so hopefully it’ll be easy to find at a glance! There’s also a section at the end summarising the differences.



Possible sections to add in future :

If you have any suggestions for new sections or improvements to other sections, or spot any mistakes or typos, feel free to contact me. @Cyanilux on twitter. I also have a discord server.

Useful Links