More customizable shader generator

Registered by Craig Macomber

When a user wants to use a custom effect in their project, they pretty much have to abandon the shader generator and replace it from scratch. A way to include custom shader code within the generated shaders would solve this problem. This could be done by using a special shader file in a custom format that would provide shader code which the shader generator would wrap in methods and call.

The current plan has several parts:

Shader Builder:
Loads a list of nodes and links which make a cycle free directed graph describing all possible shaders that it can generate and when to generate what.
Accepts a RenderState object (which describes what features/inputs are available at some node in the scene graph, as well as any flags) and returns a shader.

Editor GUI:
Not needed for initial functionality, but it would be nice to have some sort of editor. Coding of nodes will be done in text files, but connecting them up, and perhaps tuning parameters could be done in a GUI.

AutoShader:
Some tool that can be given a node and a shader builder, and will apply shaders as appropriate to its children. It would also be good for it to be able to accept an updated Shader Builder for realtime updating/previewing of shaders. It can also provide additional functionality such as setting/updating/adding shader inputs. How requirements for such actions associated with shader nodes will work is not exactly clear.

Loader:
Loads graphs into a form supported by Shader Builder.

The a node library, which will contain a set of nodes available to use in a shader graph will consist of a folder full of text files, and/or folders which will be recursively walked, parsed, concatenated into one large set of node definitions + and desired helper functions. A convention of putting all nodes that need to use helper functions inside the same file, or in a folder together, and prefixing the helpers with the folder/file names should keep things from conflicting.

Packager:
For deployment, a packager should be provided that will take the saved graphs and the nodes library, and strip the unused parts (from both the graphs and the library), and concatenate the library into a single file. This is not necessary, but will keep file sizes slightly smaller, as well as improve load speeds.

Details+Features
Custom nodes can be added. This means you can easily get any custom effects you need into shaders. All things that need shaders could potentially use the system if desired (filters, deferred lights etc). All the stages of shaders are generated and can be customized (vshader, fshader and an others you want).

It should be possible to support composite nodes, meaning one node in the shader graph could be defined from a collections of nodes hierarchically.

How this design differs from standard drag and drop tree based shader generator GUI tools (based on guesses about what such tools actually do):
- It supports all stages of shaders.
-Nodes can base their behavior on the RenderState before code generation. Example, if there is a flag that says you don't need the wind vertex shader effect, none of its code, of the code needed to provide it with values will be generated. There can even be LOD settings that can cause it to select different code, disable effects etc. One graph describes many possible shaders, not just one.
-It supports arbitrary shader input and outputs. This means its fine for dealing with aux buffers, passing from vshader to fshader, getting all those handy transform matrixes etc.

Status: I have a shader generator, however a new version matching the outlined design is being implemented from scratch. New version lives at this link:
https://github.com/Craig-Macomber/Panda3D-Shader-Generator/tree/v3/
Loader and ShaderBuilder are finished, and lightly tested. It can load the library of NodeTypes, and a graph file, and produce shaders for RenderStates with decent caching. It can also save graph files, though there is currently no editor for editing while loaded. Current focus is on content. Some useful and diverse content (NodeTypes, NodeType classes and graphs) need to be produced to demo and finish testing.

Blueprint information

Status:
Started
Approver:
None
Priority:
Undefined
Drafter:
Craig Macomber
Direction:
Needs approval
Assignee:
Craig Macomber
Definition:
New
Series goal:
None
Implementation:
Good progress
Milestone target:
None
Started by
Craig Macomber

Related branches

Sprints

Whiteboard

(Craig) - Functional but not feature complete, well tested or documented. Source pushed to: http://github.com/Craig-Macomber/Panda3D-Shader-Generator

Project has been cleaned up and split into distinct parts (as modules in shadereffects package)
shadereffects: The core. Contains classes to represent effects, and tools for generating source from them
txteffects: a text file based effects loader. Creates shadereffects.ShaderEffect instances with all needed input and params
pandautil: makes panda shader objects, caches shaders, and optionally writes out shader source for debugging

There are also some other less polished modules:
effectPlacement: at attempt at writing an auto shader generator for selecting and applying effects to the scene graph. Functional, but needs API work. Its a bit messy to use
pyEffects: an effects loader (alternative to txteffects) that loads effects along with effectPlacement filters from python files. I'd like a replacement for this approach thats not reliant on python, and is easier to use. Again, effectPlacement API issues
filter_: helper for effectPlacement for deciding which effects to place on each node.

effects files (for txteffects) now include basic normal based lighting, tinting, coloring, single texturing, ambient lighting, threshold alpha and over-bright to alpha (those last 2 let you use bloom filters easily).

Regular panda ambient and directional lights effects now functional and included. Some specular issues are present though, but its an effect issue, not a shader generator one.

Still needs support for multiply applying the same effect, both for hooking up multiple inputs (like lights), and for simply doing something multiple times in a row or in different places to different sub effects.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.