![Very Happy :D](./images/smilies/icon_biggrin.gif)
Newbie to directx programming I guess.
Code: Select all
//! Solid 2 layer material renderer
class CD3D9MaterialRenderer_SOLID_2_LAYER : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_SOLID_2_LAYER(IDirect3DDevice9* p, video::IVideoDriver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA);
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
};
Code: Select all
//! Solid 2 layer material renderer
class CD3D9MaterialRenderer_SOLID_2_LAYER : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_SOLID_2_LAYER(IDirect3DDevice9* p, video::IVideoDriver* d)
: CD3D9MaterialRenderer(p, d) {}
//virtual void OnSetMaterial(SMaterial& material, const SMaterial& lastMaterial,
// bool resetAllRenderstates, IMaterialRendererServices* services)
//{
// if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
// {
// pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
// pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
// pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
// pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
// pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA);
// pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
// }
// services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
//}
virtual void OnSetMaterial(SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
// base texture( texture stage 0, normal operations, but save them to the temp register )
pID3DDevice->SetTextureStageState( 0, D3DTSS_RESULTARG, D3DTA_TEMP );
// alpha texture( texture stage 1, we just need to grab the alpha value from the texture at this stage
pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
// this the the blend texture, we want to blend this color with the color from texture stage 0( which is
// in the temp register ) using the alpha we got from texture stage 1.
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_TEMP );
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
virtual void OnUnsetMaterial()
{
// base texture( texture stage 0, return the target to current, rather than the temp register )
pID3DDevice->SetTextureStageState( 0, D3DTSS_RESULTARG, D3DTA_CURRENT );
pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pID3DDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_CURRENT );
}
};
Code: Select all
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNodeRAW( "D:\\Terrain\\FreeWorldExports\\terrain\\heightmap16bit.raw" );
terrain->setMaterialFlag( video::EMF_LIGHTING, false );
terrain->setMaterialTexture( 0, driver->getTexture( "D:\\Terrain\\FreeWorldExports\\terrain\\Base.bmp" ) );
driver->setRAWImagerLoaderParams( 512, 512, 8 );
terrain->setMaterialTexture( 1, driver->getTexture( "D:\\Terrain\\FreeWorldExports\\terrain\\Alpha_alpha.raw" ) );
terrain->setMaterialTexture( 2, driver->getTexture( "D:\\Terrain\\FreeWorldExports\\terrain\\Alpha.bmp" ) );
terrain->setMaterialType( video::EMT_TEXTURE_SPLAT_2 );
Code: Select all
node->getMaterial(0).Texture1 = texture1;
node->getMaterial(0).Texture2 = texture2;
node->getMaterial(0).Texture3 = texture3;
node->getMaterial(0).MaterialType = video::EMT_SOLID_2_LAYER;