Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm still in the planning phase for a hobby abstract renderer, and i'm wondering how i should handle multiple vertex types and different shader inputs. (This is my first graphics project, so cut me some slack for lack of knowledge :) ).

What I want to to do is have the vertices be typeless, and have my model file specify "channels" of attributes EX: position, color, normal, binormal, tanget, etc. These channels would have string identifiers and stride values. On the shader side, i would like each shader program to specify which "channels" it requires via the identifier. Vertex Buffers would be compatible with the shaders if they had all the attributes required by the shader.

this is all abstract so I must be able to implement the functionality in most API's. However, taking a look over at D3D11, it looks like i would have to create a new Input layout per Vertex Buffer/ Shader COMBINATION. It would also mean some sort of goofy cataloguing system that goes, "if you have this specific combination of attribs, and the shader requires this specific combination of attribs, then use this layout", which makes me a little queasy thinking about it :\ . The number of input layouts would grow exponentially with more combinations.

The other solution would be to create and delete a new input layout EVERY time you wish to render. same queasiness -_-. Was D3D11 intentionally trying to force every vertex buffer in your design to have the same type?

Does anyone have a better suggestion? the main parameters i would like are the channel based vertex buffers, and the channel receiving shaders.

share|improve this question
Do you really need to be able to use arbitrary shaders with arbitrary assets? Many engines specify which shader an asset uses in the data of the asset, or use default values when data is not given, e.g. using a white 1x1 texture when no material/texture is specified in the asset. Often, all assets follow a certain standard, e.g. all assets contain a certain minimum of data. I'm not sure wether it would be worth the hassle. – sarahm Mar 5 '13 at 10:22
Eventho loading shaders is not "that expensive", if you have multiple shaders it's preferable to load shader A, update constant buffers, put data into index/vertex buffers, draw/drawindexed then load shader B etc. If you want to decide which shader to use at runtime per model or even vertex, you performance will suffer. – Lufi Mar 5 '13 at 13:10
I would say that a buffer could NOT use any arbitrary shader, but i would like them to be able to use a subset of them. Ex: Any object with a color channel can use a simple color shader, any object with tex coords can use an unlit texture shader, but only objects with a material file can use certain shaders like bump mapping shaders or light shaders or reflection, and so on. However, it seems as though if i have, for example, a model that just has Pos, color and a model has Pos, color, normal, tex, i would need two input layouts for one simple color shader – FatalCatharsis Mar 5 '13 at 15:12
up vote 2 down vote accepted

This sounds like you are talking about a Flexible Vertex Format (FVF). This allows you to define you vertexes as you would like, though this is for D3D9 rather than for D3D11.

One thing to keep in mind is not to have things too dynamic. The reason is, the more vertex formats that are the same, the more models that share the same texture/shader/material etc... the faster things can be rendered.

If you are going to use standard model formats, a common FVF should be all you need:


Regarding shaders, they are custom built for specific models and vertex formats. For best performance, they expect things to be precise, rather than, "Which FVF am I using?"

Performance is King.

share|improve this answer
FVF is D3D9, the question is about D3D11. – Le Comte du Merde-fou Mar 5 '13 at 13:22
@mh01 thanks, updated answer – rhughes Mar 6 '13 at 15:13
I'd rather not force models to have superfluous data when it doesn't need it. If every model had to have a position, color, normal, binormal, tangent, tex0, tex1, and so on, and all it needed were 3 of those, that would just be wasted memory and hard drive space. It may be a little slower to have multiple model types, but the amount of memory and hard disk space saved may be worth it. At this point, i do not know and i'm weighing the balance as i go. If it becomes simply too taxing, i will probably use a uniform vertex type for all models. Only time will tell :). – FatalCatharsis Mar 10 '13 at 6:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.