need help on alpha blending

Started by
1 comment, last by yuppies 18 years, 6 months ago
ive implemented my terrain texture by tiling the texture and using alpha maps to blend texture using a multi-pass texturing but the problem now is the whole terrain mesh becomes transparent and i can now see whats behind the hill or the terrain mesh any suggestion on what possibly goes wrong with my implementation? heres how i set my texture and my renderstate:

m_pGraphics->GetDevice( )->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	m_pGraphics->GetDevice( )->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	m_pGraphics->GetDevice( )->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
		
	m_pGraphics->GetDevice( )->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
	m_pGraphics->GetDevice( )->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);	
	
	m_pGraphics->GetDevice( )->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
	m_pGraphics->GetDevice( )->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);	
	
	m_pGraphics->GetDevice( )->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
	m_pGraphics->GetDevice( )->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

	m_pGraphics->GetDevice( )->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	m_pGraphics->GetDevice( )->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
	m_pGraphics->GetDevice( )->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
	m_pGraphics->GetDevice( )->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

	m_pGraphics->GetDevice( )->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
	m_pGraphics->GetDevice( )->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);


Advertisement
If your doing what i think your doing, you probly get this problem where you want more than one texture. If thats whats happening then, you probly are rendering one section kinda with an alpha channel of one setting, than the other alpha channel is the inverse of this alpha channel. But if you render it, the first pass will look like it should, with all the alpha blending right. But the second pass is where it screws up. What should be 50% from one texture and 50% from another is really 25% from the image rendered beforethe texture was rendered, 25% from the first rendered terrain texture, and 50% from the last terrain rendered. This happens because the second pass doesn't add up with the alpha, it is 50% of the already rendered texture.

So to fix this, you should render the first terrain texture at a full 100% alpha. Then render the second, third, and however many textures after that with their original alpha values. Hope this helps.
so what happens now is this if i render my first/base texture at 100% then blending is not good what i mean is.. since the grass texture( the base texture ) is rendered with 100% alpha and lets say for example i render the mud texture( at second pass ) at with also 100 the mud texture also looks like a grass texture with the color of the mud texture..
is this supposedly the result?

This topic is closed to new replies.

Advertisement