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: https://gist.github.com/runewake2/68423db7c32d80993333a1c932f032d1

The official blog post on Shader Graph Custom Nodes can be found here: https://blogs.unity3d.com/2018/03/27/shader-graph-custom-node-api-using-the-code-function-node/

Unity goes into even more depth on the CodeFunctionNode on their GitHub page: https://github.com/Unity-Technologies/ShaderGraph/wiki/Custom-Nodes-With-CodeFunctionNode

Join the World of Zero Discord channel: https://discord.gg/hU5Kq2u


Sam Wronski
WRITTEN BY
Sam Wronski
Maker of things, currently helping build cloud things @ Google. World of Zero is a personal project disconnected from my professional work. Lets make something awesome together!