• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# stumped on tile blending

## Recommended Posts

All. I must be with stupid, cuz multitexture blending is an old topic, and it seems simple enough, but I must be missing something... I'm basically trying to do what other's have done before me: Blend two textures so that I don't have to make transition tiles(ie, grass to sand, sand to water) I'm using two graphics files, grasstrans.png - grass texture with a gradient alpha channel sand.png - sand texture with a solid alpha channel The sand.png is in texture stage 0(m_pBaseTexture) The grasstrans.png is in texture stage 1(m_pBlendTexture) They are set every render phase:
if (m_pBaseTexture)
g_pDevice->SetTexture(0, m_pBaseTexture);
if (m_pBlendTexture)
g_pDevice->SetTexture(1, m_pBlendTexture);

And in my initialization phase, I have the following:
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
m_pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
m_pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);

m_pDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pDevice->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
m_pDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_BLENDTEXTUREALPHA);
m_pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
m_pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);

I explicitly set everything, just to make sure that it's doing what I want. However...it's not. Even if I exchange the places of the textures in the texture cascade, and I change stage 1's(The second stage)alpha operation to D3DTSS_SELECTARG2, I just get a gradient alpha of the sand.png average COLOR, but not the sand texture. And in any case, it seem like I can only see the texture of only stage 0(the first stage). Oh yeah...and my video card should support multitexturing(since I was able to do operations on colors, just not the alphas), and all the diffuse colors in the verticies are set to opaque white(255,255,255,255) What am I missing? Maybe the entire approach is wrong? Thanks in advance for anyone that can knock the stupid out of me. Wil Edited by - iamwil on December 13, 2001 10:10:32 AM Edited by - iamwil on December 13, 2001 10:17:33 AM

##### Share on other sites
The sand texture is being set at stage 0 which is being neglected at stage 1 by the use of D3DTOP_SELECTARG1. Use D3DTOP_BLENDTEXTUREALPHA for the color operation at stage 1.

##### Share on other sites
Doh. I''m writing to myself.

Anyways, in case anyone else runs into the problem, I did end up doing a quick fix with multipass rendering instead of multitexture rendering.

Here''s a screenshot

Right now, this ''acre'' in the screenshot is 20 x 20 tiles, where each tile consists of 2 triangles, with a bitmap stretched over the entire arce. So that''s 800 triangles, and with only the base texture(the yellow sand texture), the frame rate was about 130 fps. But as you can see in the screenshot, with 2 renders, I only get about 70 fps.

So the question still stands, does anyone know how to do this same effect, but with multitexturing? I can''t seem to get it to work.

Wil

##### Share on other sites
quote:
Original post by FantasyGuy
The sand texture is being set at stage 0 which is being neglected at stage 1 by the use of D3DTOP_SELECTARG1. Use D3DTOP_BLENDTEXTUREALPHA for the color operation at stage 1.

Quite right. I did try your suggestion, but I couldn''t get it to work. I remember why I originally tried to set stage 1 to D3DTOP_SELECTARG1. I did this:
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);m_pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);m_pDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);

Now, if I do this:
m_pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG2);

I should get the sand texture(which I do).

But if I do this:
m_pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);

I should get the transparent grass texture(which I don''t).

Instead, I get a transparent black texture(hard to see). Am I right in thinking that I should get a gradient transparent grass texture? I''m guessing that the transparency IS working...it''s just that the texture isn''t being rendered somehow in texture stage 1. Is there some setting I have to do...like a material or a lighting to each texture stage? I thought that once you set a material and light, it applies to all stages...right? The first argument of SetLight() is the index to the light, not which texture stage it illuminates...so I''m still stumped. Anyone got other suggestions? I''ll willing to try anything.

##### Share on other sites
Sorry, the last post was by me.

##### Share on other sites
Yay! I got it to work. To let subsequent newbies reading this know, my problem was that I didn''t have the correct vertex format(damn!) After I did that, everything worked out great. I get the same effect, and I''m getting ~250fps

The flexible vertex format that I used was:
#define TILEVERTEX_TYPE (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEXTUREFORMAT2 | D3DFVF_TEX2 )

The SetTextures that I ended up with are:
	m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);			// use of alpha blending	m_pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);	m_pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);	m_pDevice->SetRenderState(D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB(128, 255, 255, 255));	m_pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);	m_pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);	m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);	m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);	m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);	m_pDevice->SetTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);	m_pDevice->SetTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);	m_pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);	m_pDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);	m_pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);

I didn''t need to do any alpha ops since the alpha was contained in the *.png files

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627677
• Total Posts
2978590

• 11
• 12
• 10
• 12
• 22