one vertex and 2 textures: beginner question...

I'm learning direct3d9, and i'm trying to make a "3ds view" application, that loads .3ds files and displays it. It's working fine now, I learned a lot, but today I got a very confusing doubt:

Imagine you have:

  1. two faces, let's say face A (with texture 1 - large texture, high tiling) and face B (with texture 2 - no tiling);
  2. one vertex that belongs to the faces A and B;
  3. the flexible vertex format used is:

struct Vertex {

       D3DXVECTOR3 position, normal;

       float u, v;  //texture coordinates

};

The question: how can the same vertex share the texture coordinates for the two faces to witch it belongs



Answer this question

one vertex and 2 textures: beginner question...

  • quresh

    Well, the maximum number of texture coordinate sets contained in a vertex declaration using the fixed function pipeline is 8 if I'm not mistaken. If you would use shaders, you might be able to "disguise" other texture coordinate sets using different vertex declaration usage parameters and then "decode" these in the pixel shader. (I say might, because I have never tried something like this.)

    The number of textures you can use is infinite if you go for multi-pass rendering, but the number of texture coordinate sets in a single vertex declaration is limited and has to be set for a vertex buffer, otherwise there would be no way to tell the uniform memory used by each vertex in the buffer. You could easily use the D3DVERTEXDECLARATION9 thingy that's replacing FVF to set the number of texture coordinate sets in the declaration at load-mesh-time to the number of texture coordinate sets in the .3DS file.

    This way, you can't support more than 8 texture coordinate sets per geometry data. If you really needed more, you could go for duplicate vertex buffers with different texture coordinates using multiple vertex data streams or use the technique of composing vertex data from multiple vertex buffers using streams described in the Instancing sample and topic in the DirectX SDK.


  • john cov

    This is usually acommodated by using two texture coordinate sets (u1, v1 and u2, v2 for example) in your flexible vertex format.

    If there is a mathematical relationship between the texture coordinates for Texture 1 and the texture coordinates used to apply Texture 2, then you could store only a single set of texture coordinates and use shaders to calculate the others (this is the case when you know the number of tile instances in both directions for example).


  • S.S. Ahmed

    but in my case, the number of texture sets is undefined, because there may be an indefinite number of textures applied to the same vertex...
  • one vertex and 2 textures: beginner question...