I have added a new material to the material renderer, and that part works fine. I am trying to use 3 materials on a terrain node, but that doesnt seem to work. I have looked over the smaterial code and it looks like it supports up to 4 materials.
Am I misinterpreting it? Having added a new material, shouldnt it now support more materials on a node?
Number of materials question
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
What do you mean with node - scene node? A scene node supports an arbitrary number of materials (using mesh buffers you can have an array of mesh buffers each with its own material). I think you mean three textures per face. This should be possible, however Irrlicht had some problems with more than 2 textures under OpenGL in version 1.1. Use Irrlicht SVN for that. With D3D it did not show any problems, although I also did not check if a material would support more than 2 textures.
-
- Posts: 14
- Joined: Wed Sep 27, 2006 1:30 am
Sorry about using imprecise langauge. I am adding three materials to an ITerrainSceneNode. I will list the code I use to extend IMaterialRenderer.
The code works fine for two materials, but I cannot seem to get a third to work no matter what.
The code works fine for two materials, but I cannot seem to get a third to work no matter what.
Code: Select all
namespace irr
{
namespace video
{
//CD3D_Materials
class CD3D_Materials : public IMaterialRenderer
{
public:
CD3D_Materials(IDirect3DDevice9* _device,video::IVideoDriver* _driver)
: device(_device),driver(_driver)
{
}
~CD3D_Materials()
{
}
protected:
//Members
IDirect3DDevice9* device;
video::IVideoDriver* driver;
};
//CD3D_Materials
//CD3D_Materials_Solid_3_Layer
class CD3D_Materials_Solid_3_Layer : public CD3D_Materials
{
public:
CD3D_Materials_Solid_3_Layer(IDirect3DDevice9* p,video::IVideoDriver* d)
: CD3D_Materials(p,d){}
virtual void OnSetMaterial(SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
device->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE);
device->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
device->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
device->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
device->SetTextureStageState (1, D3DTSS_COLOROP,D3DTOP_MODULATE);
device->SetTextureStageState (1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
device->SetTextureStageState (1, D3DTSS_COLORARG2, D3DTA_CURRENT);
device->SetTextureStageState (1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
device->SetTextureStageState (2, D3DTSS_COLOROP,D3DTOP_MODULATE);
device->SetTextureStageState (2, D3DTSS_COLORARG1, D3DTA_TEXTURE);
device->SetTextureStageState (2, D3DTSS_COLORARG2, D3DTA_CURRENT);
device->SetTextureStageState (2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
device->SetTextureStageState (3, D3DTSS_COLOROP,D3DTOP_DISABLE);
device->SetTextureStageState (3, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
};
//CD3D_Materials_Solid_3_Layer
}//namespace video
}//namespace irr