A while ago I wrote my own shader generator for Panda: https://github.com/Craig-Macomber/Panda3D-Shader-Generator
Blueprint: https://blueprints.launchpad.net/panda3d/+spec/more-customizable-shader-generator
Recently the topic came up again, and rdb pointed to this: http://www.blender.org/typo3temp/pics/923052fa19.png
(A video of a similar concept located by Anon here: moddb.com/engines/source/new … n-released )
With Panda 2 in the works: https://launchpad.net/panda3d/2.0.x
I figured I should sort out what it really is that we want.
How about this:
A graphical editor (like rdb showed), but with separate stages for each phase of the shaders (vertex, geom, and fragment). Graphically between the stages would be shown any intermediate values (passed between the shader stages), and the list of them would be editable.
The editor presents a directed graph of nodes, which can have an arbitrary number of inputs and outputs. Collections of nodes in this graph can be packaged up into composite nodes for easy reuse and organization. Composite nodes could be double clicked to edit their contents. Each node is a code generator, that can use the render state and tags to choose what to generate.
Some nodes in this directed graph would be shader inputs, including tags (shader inputs with no associated value, but simply placed on nodes to mark them). When applying the shader generator to a NodePath, parts of the shader graph that depend on shader inputs that are not present will be considered deactivated. To deal with this, there will be some special node types in the shader graph, such as one that takes a value that may or may not be active (not disables) and a default to use when the input is deactivated. This will allow it to do things like the current shader generator does. If there is a normal map, it will activate the normal map nodes, if there is a color scale… if there is a gloss map… but it will also enable more complex stuff, including user defined effects.
One example would be to tag node paths for tessellation in the geometry shader, or to write a custom vertex shader effect for wind deformations.
The editor is provided in such a way that you can import it into your game, and ask it to put up a live editor. It would also be able to run as a standalone, or perhaps as a live editor on something like pview to generate and save shader generator configurations.
Design:
Current approach is to implement a graphical shader meta-language (a language in which shader code generators can easily be written). With no conditionals, it amounts to the same thing as linked there, but conditional nodes allow you to generate different code depending on what textures, shader inputs, and tags are present. Hand written conditional logic (in the form of NodeType subclasses), custom NodeTypes with CG code from the library files, and graph files showing the configuration from the editor together make up the source code of the meta-language which is compiled at runtime into a ShaderBuilder object which you can use like panda’s existing shader generator to generate the desired effects of different nodes.
I’ve designed a powerful system for efficient code generation time computation and conditionals. The links in the graph structure get status values as the graph is processed to generate the code. This allows avoiding generating the parts of the code that are not used, as well as potentially allowing customizable generation time computation. This could be used for things like pre-computing constants that get compiled right into the CG code.
Open Issues:
What about CPU side effects? Multi pass effects? Post process? Animation? The best approach for things that need to work together between CPU and shaders would be to apply the effect on the CPU, and include a tag on the nodes that the shader generator can pick up on and act accordingly. An example would be billboards, they get a compass effect and some tag so the correct shader can be made.
Post processes could be done just fine with the shader generator applied to a full screen quad + Panda’s existing post process tools.
So what do you want from a shader generator/editor? Does this cover it?
Please post comments, questions, suggestions and issues.