Combining both Vertex and Texture Alpha Operations...

Started by
1 comment, last by Ailus 16 years, 10 months ago
Hey everyone, Currently I'm making a tiling engine for my game engine (both Isometric and Top-Down modes for maximal expansion of content later on), but I'm stuck with a dilemma: I can't seem to figure out how to set the Texture Stage State so I can both set the Alpha values of a surface (really just two polys to form a quad, not a real DX surface) by both its Texture alpha channel (if it has one) and by its Vertex Alpha Values (If its different from 0xFF). I was trying to find some way to add in vertex alpha values to the CUSTOMVERTEX struct:

	struct CUSTOMVERTEX
	{
		float x, y, z;
		DWORD dwColor;
		float u,v;
	};
but alas nothing worked (I don't think its even possible?). So then I decided to use the regular old diffuse channel approach to vertex alpha blending, and I set it up and it works for the most part, except that it cancels out the Texture alpha blending operations, which I also wanted. Here's what I got for my Texture Stage State:

	m_pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1);
	m_pD3DDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
	m_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
	//m_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1, D3DTA_TEXTURE); IGNORE
	m_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);
which gives me the effect described above, canceling out the texture alpha channel. So then I tried to get creative by trying to average the ALPHAARG1 settings, such as by doing this:
m_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,(D3DTA_DIFFUSE*D3DTA_TEXTURE)/2);
or

m_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,(D3DTA_DIFFUSE & D3DTA_TEXTURE);
But still nothing worked the way I wanted it to. So here I am now. Basically what I want is to be able to set a quad's (two poly's) alpha values by its Texture if it has an alpha channel and also by the vertexes if I set it differently than 0xFF (or 100% opaque). Anyone have any suggestions or ideas on how to accomplish this?
Advertisement
Did you try something like :

m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

? Texture Alpha * Diffuse Alpha
Wow that worked just the way I wanted it to! =] Thanks a bunch!

Guess I missed that option "D3DTOP_MODULATE" in the MSDN libraries. Next time I'll be sure to read up a bit more thoroughly.

Edit: Actually I missed the whole page on D3DTEXTUREOP options. There's so many! Time to have some fun experimenting =P

Thanks again!

Cheers!

This topic is closed to new replies.

Advertisement