Get over it, you’ll never have shader injection.
After countless hours of dicussion in the core chat over almost a year (or was it two?), we finally got to a point of agreement on some concept on how to make the material system more flexible and less painful to maintain.
This concept is called Shader Nodes and I recently took the shot to implement it.
Today I’m fairly happy with what is done and I just made the commits of the whole system into the repo.
So....what on earth is it?
Shader nodes are self contained units of shader code that take inputs and give outputs.
With this new system, you don’t write a shader, you assemble shader nodes and the system generates a shader for you.
A shader node adds a feature to your shader, it can go from a simple texture fetch to hardware skinning for example.
The nodes are connected by mappings between outputs and inputs.
So for example, let’s say you’d like to add support for fog into the unshaded material.
Just grab the material definition of the unshaded material, add the Fog shader node to it and make the relevant connections.
So from now on, we are just gonna provide shader nodes, and users will make their own material definitions with what ever node they like.
Of course, unshaded and lighting materials will be translated to this system, but you'll now have to consider them as examples of material definitions.
Note that if you are in love with monolithic shaders, you can still use them as before. The node system only work if there are no shaders defined in a technique (and ofc that shader nodes are declared)
This has several advantages :
- Very modular, build your shaders like legos.( you need at least some basic shader knowledge though)
- Make the shader code a lot more concise and easy to maintain
- You can add tons of features to your material, without having to care about the length of the code.
- You can mix up your shader nodes with stock shader nodes, still having the benefit of bug fixes of our nodes.
- It handles GLSL versions and generate the appropriate version for the GPU
- And of course... that’s friggin awesome...
I made a documentation that explains how to use them here.
It may change over time, but at least you’ll have a complete overview of what the system can do.
If you want to expriment, you have a UnshadedNodes.j3md material def in the repo, that is the unshaded material with additional fog support.
You also have experimental nodes in Common/MatDefs/ShaderNodes
I can’t talk about everything in one post because we got passed the TL;DR threshold a long time ago, so if you have questions, please ask, it will be my pleasure to answer.