Shader & Material Graph
Currently I am working on a shader and material Graph that will provide both compilable shader files, and material settings files for objects in our game, as well as providing data for things like the texture slots used by the object and the names of the shaders.
Existing solutions
For this tool I began by basing the tool off of Unreal’s material editor interface. This was primarily done as the Technical Artists in our group had more experience with it. Secondly, it already provided plenty of great examples of how a node based material editor can work and functions it provides.
Seperating Vertex and Pixel Shaders
I wanted to provide the ability to both create vertex shaders so that we can create effects such as swaying foliage as well as allowing the textured output in the pixel shader to be modified. As such I needed to define the input data for the different vertex input layouts and hook that up as a starting node.
I then wanted to keep things in sync between the vertex and pixel shader graph so that the return value for the vertex shader always matched the input for the pixel shader. In order to achieve this I created a return node at the end of each graph where the calculated data could be hooked in.
How will it work
Currently when a user “saves” the graph, the nodes iterate through and concatenate a string, this will then attempt to be compiled by the D3D compiler and if successful written to a .hlsl file. Currently I can iterate through the nodes and prints out the text that the nodes generate, but before I have more complex functionality implemented it will be difficulty to create a good test case.
Macro Functions
A Core feature that I am currently working to implement in this system, is the ability to create your own Macro functions, which will write to a .hlsli file, this should then be automatically linked to the other generated shader files this should help keep graphs clean, and scalable whilst functionality is easily reusable and therefore hopefully more bug free.
Currently I can create new macros, which have variable data stored in a list outside of the graph environment so that both the macro graph can access the macros to edit them and the shader graph can access them to call them.
I want to develop the system further by making it simpler to use where selected nodes in the shader graph can be “collapsed” into a macro and put into the macro graph ready for use in other shaders. additionally like in my render graphs I want to link up the Macro name to a drop down combo box to make it easier to select the wanted Macro.
Alongside this I am also working on turning simple mathematical functions and common shader calculations into nodes so that they can easily be used inside the Graph. these will be necessary to begin testing my most common use cases.
On my current task list for these nodes I have:
simple mathematics, addition multiplication division etc.
Variable, this will create a named variable inside the shader file that can be set and read from as expected, this gives the user the ability to ensure that both the graph and the generated .hlsl file is kept readable.
Gamma / Linear colour conversions
Texture sampling
Array data getters