EMT_TRANSPARENT_ALPHA_CHANNEL implementation

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Khanz

EMT_TRANSPARENT_ALPHA_CHANNEL implementation

Post by Khanz »

For implementation of this really necessary material:

1)
Open CVideoDirectX8.cpp file, line 799, instead of following lines

Code: Select all

	case EMT_TRANSPARENT_ALPHA_CHANNEL:
		// not implemented yet.
		break;
insert something like following lines (before "break"):

Code: Select all

		pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
		pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0);
		pID3DDevice->SetTransform( D3DTS_TEXTURE0, &UnitMatrix );

		pID3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_BLENDTEXTUREALPHA );
		pID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		pID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT );
		pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
		pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
		pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

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

		pID3DDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)0x00000001);
		pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); 
		pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

		pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
		pID3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
2)
Open CColorConverter.cpp, line 205 - CColorConverter::convert32BitTo16BitColorShuffle, find that line:

Code: Select all

*out = RGB16(p[2], p[1], p[0]);
and replace with

Code: Select all

*out = (p[3]) ? (RGB16(p[2], p[1], p[0]) | 0x8000) : (RGB16(p[2], p[1], p[0]) & 0x7FFF);
this works for me fine
Khanz
Posts: 3
Joined: Thu Dec 11, 2003 1:03 pm
Location: Russia, Novokuznetsk

Post by Khanz »

Small addition.

1) Others materials can be drawn incorrectly because D3DRS_ALPHATESTENABLE is TRUE after using EMT_TRANSPARENT_ALPHA_CHANNEL material.

2) The following line in prev my post actually its simply nothing does:

Code: Select all

pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
PS. Material EMT_TRANSPARENT_ALPHA_CHANNEL was implemented in 0.4.2 for 32-bit textures under DX8. So, my mistakes have fallen into 0.4.2.
sirshane
Posts: 31
Joined: Tue Oct 14, 2003 5:02 am
Contact:

Post by sirshane »

Cool. Now we need an OpenGL implementation. :)
-Shane
Post Reply