Requirements of the shader system
- Being able to structure the shader (making it relatively easy to follow).
- Making it possible to produce variations in the WGSL based on e.g. material properties and texture formats.
- The fragment shader should be able to set the output depth (but should not be the default).
- Autogenerate the WGSL for the bindings: uniforms, textures, samplers, strage buffers.
- The varyings between vertex and fragment shader are determined from which ones are used in the fragment shader (subject to the variations above).
- A way to produce fragment output in a generic way, so that what happens exactly is defined by the renderer's blend mode.
- I think, being able to produce variations in WGSL based on what render pass is active (volume renderers might need it)?
- Allow users to change the shader of an existing material for custom visualizations?
Right now, 1, 2, 3 are handled by our shader class with jinja2. We also recently added support for 4. In #200 I propose an approach for 5. And 6 is addressed in #198. Also see this comment for what the docs for this could look like.
Would be interesting to see how DAG shaders map on these requirements ...
I added:
- Allow users to change the shader of an existing material for custom visualizations?
Strictly speaking we don't need to support this, but it would be very interesting, because it would make pygfx much more versatile. This is something where node-based (aka graph-based) shaders would be good at. It might be that its also possible to realize this with templating.
Closing. I think the current system ticks all boxes. With the more recent changes where the shaders are classes, it has become easier to subclass an existing shader and modify it (nr 8 in the list).