Original Post
I am writing a 3D modeling program, and as I add new features I am wondering how to best handle them in my shader. The problem is that each new feature adds options of its own that mulitiplies the possible vertex declarations I can have. For example, all meshes have position and normal and optionally a texture. So I add the ability to render a skinned mesh with 2, 3, or 4 bone influences. So, now I have 2 x 3 possible vertex formats. Then I add normal mapping with the option to just have tangents and let the shader calculate the binormal from the tangent and normal, or have both tangents and binormals precalculated. Now I have 2 x 3 x 2 possible vertex formats. I think it is OK to declare a component in the shader function that is not really in the vertex stream. I have this to handle meshes with and without texture coordinates: OutputVS RenderMeshVS(float3 posL : POSITION0, float3 normalL : NORMAL0, float2 tex0: TEXCOORD0, uniform bool bTex) and then define techniques for both, like this: technique RenderMeshNoTexSolid { pass P0 { vertexShader = compile vs_2_0 RenderMeshVS(false); pixelShader = compile ps_2_0 RenderMeshPS(false); fillmode = solid; } } technique RenderMeshTexSolid { pass P0 { vertexShader = compile vs_2_0 RenderMeshVS(true); pixelShader = compile ps_2_0 RenderMeshPS(true); fillmode = solid; } } But can I also do something similar for skinned meshes? Can I do this: OutputTexVS RenderSkinnedMeshVS(float3 posL : POSITION0, float3 normalL : NORMAL0, float2 tex0: TEXCOORD0, float4 weights : BLENDWEIGHT0, int4 boneIndex : BLENDINDICES0, uniform bool bTex) and use a global that indicates how many bones it really has? What would it do with the int4 if I only have one int coming in because the bone only has 2 influences? Are there other ways to make it flexible? Also, can I assume that all graphics cards that support VS_2_0 can support ints? Is there a way to control what global variables are available to each technique? As I add features the number of globals grows, and I have the globals now for the skinning that must be using up space even if I am rendering a non-skinned mesh. I am not really concerned about efficiency, since it is just a modeling program, but want to be sure I don't max out the resources available on current cards that support VS and PS 2.0. Thanks.