pygfx icon indicating copy to clipboard operation
pygfx copied to clipboard

Requirements of the shader system

Open almarklein opened this issue 4 years ago • 1 comments

  1. Being able to structure the shader (making it relatively easy to follow).
  2. Making it possible to produce variations in the WGSL based on e.g. material properties and texture formats.
  3. The fragment shader should be able to set the output depth (but should not be the default).
  4. Autogenerate the WGSL for the bindings: uniforms, textures, samplers, strage buffers.
  5. The varyings between vertex and fragment shader are determined from which ones are used in the fragment shader (subject to the variations above).
  6. A way to produce fragment output in a generic way, so that what happens exactly is defined by the renderer's blend mode.
  7. I think, being able to produce variations in WGSL based on what render pass is active (volume renderers might need it)?
  8. 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 ...

almarklein avatar Nov 10 '21 10:11 almarklein

I added:

  1. 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.

almarklein avatar Nov 12 '21 15:11 almarklein

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).

almarklein avatar Oct 14 '22 07:10 almarklein