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 am attempting to make a map editor for my game, just so I can visualize how the end result would be.

To my world I can add cubes (2 triangles) or corners (1 triangle), which are then added to a list of the vertices to draw, and the indices are added to a list of indices. Everything draws fine here, and I can set different colours for each vertex.

I would like to implement texturing, so that when you add a primitive to the scene it will let you choose a texture (that, I can handle), but then also blend with other primitive's of different textures if they are touching (everything is on a grid).

I would guess that I would have to store the texture name for each primitive, and somehow set that texture when drawing it. But I fail to see how you can set the effects texture when you are using one DrawUserIndexedPrimitives<> to draw the entire scene.

If anyone has a work around for this, or ideas on other ways of doing this, you help would be greatly appreciated.

Edit 1

I have incorporated the technique from this website here - (similar to Blau's answer below), and have the current working result...


Which maps to this...

Texture Mapping

Using each color channel as a texture..

Output = tex2D(TextureSampler0, input.TexCoords) * input.Color.r;
Output += tex2D(TextureSampler1, input.TexCoords) * input.Color.g;
Output += tex2D(TextureSampler2, input.TexCoords) * input.Color.b;
Output += tex2D(TextureSampler3, input.TexCoords) * input.Color.a;

But doing it this way means I can only be setting 4 textures to blend together each DrawPrimitives call.

Is there another way I can achieve multi texturing with more than 4 (preferably unlimited) textures? I know this is possible, as games like C&C generals allow you to set textures anywhere you want on the map.



share|improve this question
is easy to add more blending textures, but usually has no sense, you rarely will find a situation where you need to blend more than four textures per vertex. – Blau Jan 15 '12 at 15:02
Why would you say that? Because unless there is some other way of achieving the effect I want, this looks the only way. – FrenchyNZ Jan 15 '12 at 17:37
do you really need to apply more than four textures to a vertex at the same time? I suppose you realize that your vertex should not be restricted to use the same four textures ever, only to use four at the same time. – Blau Jan 15 '12 at 19:52
And of course, you can use a texture atlas to index textures, or four texture atlas, you only have to organize your sprites a bit. :) – Blau Jan 15 '12 at 19:58
I understand that a vertex should not be restricted to four textures, What I don't understand is to take in the textures that are at the same position of each vertex in a way that does not require color mapping. I guess I will have to use something like a TextureWeight array. But does that mean I have to change the size of the array each time I add a new texture? Or am I missing something here? – FrenchyNZ Jan 15 '12 at 20:47
up vote 2 down vote accepted

You can add to your vertex these arrays:

   int[4] TextureId;
   float[4] TextureWeight;

and in your shader you can do the blend,

  finalTexColor = tex0sample * TextureWeight[0] + tex1sample * TextureWeight[1] +tex2sample * TextureWeight[2] + tex3sample * TextureWeight[3]

you can see this article to know how.

share|improve this answer

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.