Recommended Posts

Hi all, I have two questions regarding the subject.
1: How do I have to set the texture stages to blend two (or more) textures together?
2: I need this for a terrain engine where I have a big vertex buffer for all the data. But if I want to blend more textures together I'd have to use more vertex buffers to store the alpha. In the dx sdk I read that it is possible to use more vertex buffers to seperate the vertex data, and this buffers are interleaved for rendering. Unfortunetly there are no examples on how to do it, so does someone know? And is this method slower then normal vertex buffers?
Spe

g_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);//Use the first set of texture coords g_pd3dDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);//Use the first set of texture coords

Share this post

Link to post

Share on other sites

If you can limit yourself to 4 textures active at once, you don't need more storage, as there are some tricks you can do... Now, not necessarily 4 for the entire landscape, but draw with one set of 4, draw again with another set of 4, etc. Only 4 active on one chunk of terrain. For best performance you'll want to render sections that use 1 texture with just the 1 texture, section that use 2 textures, with just the two. We had a 4 textures everywhere system on our last game, and really, it's a huge waste shader and memory bandwidth to mix in 3 textures at 0%, 80% of the time. Nearly 50% of our frame time was spent drawing ground.

If you're using a shader capable card, you'll have 4 texture available at once (GeForce3+). In this case simply mix one texture by diffuse.a, and one by diffuse.b using blue replicate (ps 1.1 shader supports this), then use a DP3 with 1,0,0,0 to get your diffuse.r into an alpha channel, mix with that, and use DP3 with 0,1,0,0 to get diffuse.g into an alpha channel and mix with that.

If you need more that 4 textures, you're looking at cards which support ps.2.0 anyway. Simply put more data into the VB as color1 (aka specular), a texture coord, or whatever you want. Blending more textures with the fixed pipeline will likely be more trouble than it's worth. You will no longer need to use DP3 tricks to get at .r and .g, as I think ps.2.0 allows arbitrary swizzling.

If you're using a pre-shader card you can expect 2 texture units to be available, though often more than 2 texture stages. Texture 0 can be 100%, and texture 1 can be blended via diffuse alpha, then you can mix lighting/vertex color in stage 2.

If you're aiming for shader capable cards and using the fixed pipeline, you should be able to use the DP3 tricks and using D3DTA_CONSTANT. Any card with shaders should (I haven't checked, so just SHOULD) support constants per stage in the fixed pipeline. You can use D3DTSS_RESULTARG, and D3DTA_TEMP to calculate the DP3 into a register that won't clobber the color. You lose blue replicate this way, needing an extra dp3. So you'd do something like this