Code: Select all
class MaterialRenderer_LightMap_M2_Alpha_Ref: virtual public IMaterialRenderer {
public:
IDirect3DDevice9 *mID3DDevice;
IVideoDriver *mDriver;
MaterialRenderer_LightMap_M2_Alpha_Ref(IDirect3DDevice9 *dev, IVideoDriver *driver): mID3DDevice(dev),
mDriver(driver) {}
//Wrapped functions
virtual void OnSetMaterial(const SMaterial &material, const SMaterial &lastMaterial, bool resetAllRenderstates,
IMaterialRendererServices *services) {
if (material.MaterialType != lastMaterial.MaterialType ||
material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
resetAllRenderstates) {
//for alpha channel
mID3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
mID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
mID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT );
mID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
mID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
s32 refValue = core::floor32(material.MaterialTypeParam * 255);
if ( !refValue )
refValue = 127; // default value
mID3DDevice->SetRenderState(D3DRS_ALPHAREF,refValue);
mID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
mID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
// lIGHTMAPM2
mID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
mID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
mID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
mID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
mID3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
mID3DDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
//mID3DDevice->SetTextureStageState (1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
mID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
virtual void OnUnsetMaterial() {
mID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
}
virtual bool isTransparent() const {
return false;
}
};
Thanks to Nyxojaele for starting this thread:http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=27768, as I was able to build this material only after seeing his thread.