Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to create a system where I can instance a quad to the screen, however I've run into a problem. Like I said, I'm trying to instance the quad, so I'm trying to use the same geometry several times, and I'm trying to do it in one draw call. The issue is, I want some quads to use different textures, but I can't figure out how to get the data into a sampler so I can use it in the pixel shader. I figured that since we can simply pass in the 4 bytes of our IDirect3DTexture9* to set the global texture, I can do so when passing in my dynamic buffer. (Which also stores each objects world matrix and UV data) Now that I'm sending the data, I can't figure how to get it into the sampler, and I really want to assume that it's simply not possible. Is there any way I could achieve this?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

With D3D9 you can't use a texture array (which otherwise would have been my recommendation) so I'd suggest that you put your textures into a texture atlas instead. That can be ideal if you're drawing sprites or GUI items.

If that's not an option for you (e.g. you may need mipmapped or repeated textures), you could potentially call SetTexture with a different Stage for each texture you wish to use (SM3 will allow you up to 16 simultaneous textures), then add a per-instance attribute to your vertex declaration identifying the Stage to read from in your shader. That's potentially a bit messier, but it can work.

share|improve this answer
add comment

Your Answer

 
discard

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.