I'm working on implementing support for GLTF 2.0 in a hobby renderer, using Vulkan and C++. https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html
Initially, I implemented basic support for some test GLTF files. However, after reading the spec closer, I've come across some details that are tough to deal with.
Per the spec, a Node consists of one or more Meshes, and a Mesh consists of one or more Primitives. Within the same Node, each Primitive may use different vertex formats, including:
It seems to me that this creates a situation which, in order to make a robust renderer that can handle general GLTF models, one needs to create a bunch of shader permutations the various vertex formats that a Primitive may use. So far, the only idea that has occurred to me on how to avoid an explosion of shader permutations is the following:
I tried a variation on the above, and loading models was very slow. Also, seems like a brittle way to approach this.
What is another way that I can mitigate the need to, potentially, make alot of pipeline changes for a single node? and/or needing to define many shaders for all the different situations?
Each primitive is intended to be a separate draw call, likely with a separate shader program.
Notice that the primitive differs by more than just vertex attributes. The primitive includes its own material reference, so it could be a completely separate material from other primitives owned by the same mesh.
Primitives exist to offer a mechanism to include multiple materials in a single mesh, but they require separate draw calls and separate shaders to implement. This is talked about in the Meshes Overview section.