I’m thinking of how to make shader & technique authoring more pleasant. Currently there are rather many moving parts to this. You need to author the shader description xml file, then refer to the correctly named shader permutations in a technique, which is not very obvious. Some of this complexity is necessary, as you need to be able to specify different passes from the same shader (for example per pixel lighting with or without ambient.) But part of this can be improved. I’m thinking of the following and would like to hear opinions:
- Get rid of the shader description XML’s
- Consequently, it becomes impossible to enumerate all possible permutations of a shader beforehand. But this shouldn’t be a big loss.
- D3D mode only: ShaderCompiler utility is removed and instead engine takes direct dependency to the shader compiler DLL. Like before, the encountered shader variations will be compiled to binaries so that later loading is quicker.
- Advantage to the above is that we can see HLSL compile errors in the engine log, just like we see GLSL errors
- Techniques don’t refer to shader permutation names anymore. Rather, they refer to the shader resource, and give compilation defines directly. Shader reference & compilation defines can be also global to the technique to avoid repeated specifying in every pass. An example:
Old way:
<technique>
<pass name="base" vs="LitSolid" ps="LitSolid_Diff" />
<pass name="litbase" vs="LitSolid" ps="LitSolid_DiffAmbient" />
<pass name="light" vs="LitSolid" ps="LitSolid_Diff" depthtest="equal" depthwrite="false" blend="add" />
</technique>
New way:
<technique vs="LitSolid" ps="LitSolid" psdefines="DIFFMAP" />
<pass name="base" />
<pass name="litbase" psdefines="AMBIENT" />
<pass name="light" depthtest="equal" depthwrite="false" blend="add" />
</technique>
- Internally, the engine specifies more compilation defines, such as SKINNED or INSTANCED, so there are actually more permutations than specified in the technique (just like before)
- Finally, go through the existing shaders and where it makes sense, break them up + refactor common operations into functions. The LitSolid shader is already quite monstrous.