This page looks best with JavaScript enabled

Building a Custom Node in Unity's Shader Graph

 ·   ·  ☕ 2 min read

With the introduction of Shader Graph Unity also added support for Custom Nodes you can build yourself by creating custom CodeFunctionNode. By extending this class we’re able to create our own Nodes in Shader Graph that we can extend or implement in any way. In our example here we’ll be creating a very simple linear interpolation between two colors, effectively reimplementing the existing Lerp or Branch nodes depending on what you are looking for.

The cool thing about this is it allows you to really easily extend Shader Graph with cool new functions, add missing features and more. I don’t think this API is quite to the level of allowing you to add support for Tessellation or Geometry Shaders (that doesn’t seem to be the goal here), instead it makes a somewhat accessible way for you to extend your tooling and help expand it.

That said, there are some issues here. Nodes that no longer compile are removed from the graph which feels a bit… awkward. And the default API relies on reflection to function completely. I feel like this could have been wrapped in many of the modern dependency injection style of models without requiring reflection as a significant part of the API. Still, it’s nice to be available.

The code developed during this video is available here:

The official blog post on Shader Graph Custom Nodes can be found here:

Unity goes into even more depth on the CodeFunctionNode on their GitHub page:

Join the World of Zero Discord channel:

Sam Wronski
Sam Wronski
Maker of things and professional software engineer. Lets make something awesome together!