Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

Hi I am not very good with writing shaders. How would I make a shader that simply supports 2 texture coordinates so I can load up 2 different textures to be used at the same time but on different parts of my world? Right now I have 1 texturecoord variable setup and I load a texture through it using GraphicsDevice->SetTexture(0, &Texture); and making sure my VertexDeclaration and FVF both support that, but how can I add a second texture to this? Would I make it so that I make separate coordinates and link the coordinates to a texture? How would I write that?

share|improve this question
You want to use one texture to control the other two (splat mapping), you will have a hard time to create assets if you go with a too home made solution. just my 2 cents ;-) ps. you might want to check out this link… – Valmond Aug 19 '12 at 11:29

render code:

GraphicsDevice->SetTexture(0, &Texture);
GraphicsDevice->SetTexture(1, &SecondTexture);

hlsl declaration:

sampler Texture0 : register(s0);
sampler Texture1 : register(s1);

Use the vertices's other coordinates to sample Texture1.

share|improve this answer
thank you for that but could you tell me how I would write to the pixel shader that? I currently have Out.Color = tex2D(Tex0, In.Texture); How would I make it do a second texture? Would I just add Out.Color = tex2D(Tex1, In.Texture2); ? – dvds414 Aug 19 '12 at 22:13
I tried just adding under my Out.Color = tex2D(Tex0, In.Texture) Out.Color = tex2D(Tex1, In.Texture2) and it only payed attention to the last one (for obvious reasons). So how would I get it to use both samplers to output as you explained? – dvds414 Aug 19 '12 at 23:59
Well, you would need to mix the two colors into a single output. There are literally infinite ways to do that. What are you trying to achieve with your two different textures? Perhaps you should post a second question, now that you have your textures available in your shader. – Seth Battin Aug 20 '12 at 1:19
It would be nice just to get my answer here now that I have found someone that knows what they are talking about so could you please tell me how I can get the outputs into 1 thing? – dvds414 Aug 20 '12 at 1:44
I was trying to tell you that you haven't given enough information for me to answer your followup question. What are you trying to accomplish with your two textures? I think the best place for you to explain that would be another question post. – Seth Battin Aug 20 '12 at 1:50

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.