   HLSL Shaders - Max Textures
  I want to create a shader that uses multi-texturing techniques to...well multi-texture a world. My game will be a top down rpg like game with a tile based mapping technique. I want to use multi-texturing to make the terrain look "not blocky". Anyways I would like to pass in lots of textures to the shader (preferably dynamic array but not necessary). The shader would then texture the terrain based on "weights". They really wont be weights but rather more like "This is dirt" or "this is a path" and texture appropriately. I have no doubts in this working because it uses the same methods as norm terrain texturing except it now reads the values of vertices as what texture to use. My question: Is there a max number of textures you can define in a shader? I will not be using (sampling) them all for the same vertex or probably not even all at once on any given location. This would be awesome because then I can have one plane or series of vertices for the terrain that fit in the screen and just move the textures/objects across it based on the location of a player. If I decide to use height for the terrain I could also modify that in the shader (maybe). I think the right way to handle this is to make a vertex buffer and just update that buffer when the player moves. If this is the wrong way then let me know please. I am new to all this stuff but don't think I will have any issues figuring this out.   
  Are you targeting DX9, or DX10/11?   ;  I will be targeting DX 9 using XNA.   ;  Well unfortunately in D3D9 the situation is a bit complicated. In both ps_2_0 and ps_3_0, you have 16 sampler registers available. This means you can sample from a maximum of 16 textures in one pixel shader. Unfortunately it's not straightforward to dynamically choose which textures to sample in either. In ps_2_0 you have no dynamic branching available, which means that the shader has to use predication. So this means for any branch, the shader will evaluate all possible outcomes and "choose" the correct result. So in your case it would sample from all of your textures, then choose which samples to use based on your branch conditions. In ps_3_0 you do have dynamic branching, which means the shader can dynamically branch and only sample from the textures you actually need. Well at least...that's the ideal case. In reality you'll end up with a bunch of pixels evaluating both sides of the branch, since this happens whenever all of the pixels in a nearby group all take the same branch. This the performance of dynamic branching depends on the screen-space coherency of your branch.One possible option available to you is to pack multiple textures in an atlas. If you do this, then you can "select" textures by manipulating your texture coordinates (which doesn't require any branches).   ;  Thats very helpful. I think I will stick with ps_2_0 for compatibility but out of curiosity are there arrays? Can you create an array of textures and sample from them based on an index passed to the shader? I will probably just use the atlas as that seems to be the most efficient method and theres probably a good reason most game engines use them.   ;  No, texture arrays were introduced with Direct3D 10.   