Alpha Blending with Texture and Vertex

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
nullterm
Posts: 14
Joined: Tue Feb 27, 2007 12:36 pm

Alpha Blending with Texture and Vertex

Post by nullterm »

I'm trying to draw triangles with alpha blending. However, it doesn't seem that the approach I'm trying to take isn't supported:

final alpha = texture alpha x vertex alpha

There are two material options which do each one separately, but don't modulate them together. EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_TRANSPARENT_VERTEX_ALPHA.

Is there a trick I don't see, or is it not yet supported?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

It isnt suported ...unles you code your own custom material. You can add custom materials to engine but for what you want you probably gona need shaders.
IPv6
Posts: 188
Joined: Tue Aug 08, 2006 11:58 am

Post by IPv6 »

heh, i looked for this type of material too... finishing by adding my own material. it is easy. DX8/9. It would be great to find OpenGL analog!

Main method (other are obvoius)

Code: Select all

void CSpriteMaterial_Transparent::OnSetMaterial(irr::video::SMaterial& material, const irr::video::SMaterial& lastMaterial, bool resetAllRenderstates, irr::video::IMaterialRendererServices* services)
{
	services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
	if (material.MaterialType != lastMaterial.MaterialType 
		|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam
		|| resetAllRenderstates)
	{

		if(pID3DDevice8){
			{

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

				pID3DDevice8->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
				pID3DDevice8->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

				pID3DDevice8->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
				pID3DDevice8->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
				pID3DDevice8->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
			}
		}
	}
}
Alpha-enabled texture is blended with vertex color alpha
GameRotor-Games and more...
Wiredplane-Shareware utilities...
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

IPv6 >> woul it be possible to create material which would blend texture with vertex color? (RGB components not alpha)
Post Reply