duality icon indicating copy to clipboard operation
duality copied to clipboard

Refactor Shader / DrawTechnique Resources

Open ilexp opened this issue 8 years ago • 2 comments

Summary

The current rendering resources related to shaders are needlessly convoluted: For a simple shader, the user needs to create a new FragmentShader, VertexShader, ShaderProgram and DrawTechnique resource, two of which don't really add a lot of value. Find a way to unify them.

Analysis

This feature is very much wip / concept phase. Feedback and contributions to the thought process appreciated.

First Draft

  • All four of the above resources could be unified into a single text-based drawing technique description file.
  • The file format could simply consist of a flat list of sections, each with one parameter subsection and one shader subsection.
  • There is one subsection per shader(-program) and one general subsection that is shared by all in both parameters and code.
    • Internally, every shader subsection is compiled into a distinct shader program.
    • Each program section must contain at least one of vertex or a fragment shader main functions, and can contain both, if both are needed.
    • The general section must not contain any main functions, but can contain shared code for all of the programs.
  • Parameters include the blending mode to use, depth- and alpha test settings and similar.
    • Which function are main functions for vertex and fragment shaders is specified via parameter.
    • Custom parameters can be added to be evaluated by the core.
    • If a parameter is present in both the general section and a shader section, the value from the shader section will be used.
  • Allow to specify "base techniques".
    • The general section will be merged with the current one's.
    • The shader sections will be included as-is.
    • Ideally, this would happen at the resource level (rename resources, etc.), but there could be a hint parameter in the source file that gets parsed by the importer to form a bridge.
  • Whatever the format will look like in the end, it should not throw off syntax highlighters for GLSL, so they can still be used.

Benefits

  • Unified file that fully describes how a material is rendered.
  • Full overview in the text editor.
  • Less noise in the Project View.
  • Opportunity to easily sneak in shared base functionality.
  • Potential for future multi-pass rendering of objects by specifying a RenderStep ID (or similar) per shader section and letting the graphics backend pick the appropriate one.

Attachments

  • Slightly related: issue #219

ilexp avatar Jan 24 '17 17:01 ilexp

Note: A first step that doesn't require too much engineering and design would be to merge ShaderProgram into DrawTechnique.

Also note that the draft in this issue needs to be revisited after issue #219 made some progress on how shaders are handled.

ilexp avatar Jan 06 '18 15:01 ilexp

Progress

  • Merged all functionality of ShaderProgram into DrawTechnique.
  • Removed ShaderProgram entirely.
  • Updated all sample projects to match.

Immediate ToDo

  • Re-evaluate the first draft that was outlines in the initial description and decide whether this should be pursued any further.
  • If the answer is yes, draft a solid design.

Moving this to the Future milestone, as this is for the most part a big new feature. Breaking, but not necessary or pressing enough for v3.0.

ilexp avatar Feb 02 '18 18:02 ilexp