Transparent Textures
Transparent Textures
I'm trying to create a transparent texture which contains a row of chairs and apply that texture to a material within a model of an arena. So far I've been unable to achieve the desired effect. The result is that what should be the transparent color turns black, not transparent. Also from certian camera angles the black changes to red (the color key).
Basically I need to be able to create a texture with some transparent areas and apply it to materials within my mesh. I don't want to model individual chairs. The code I'm currently testing is below.
Thanks,
-Brian
int main() {
const int FLOOR_SEATS = 12;
IrrlichtDevice *device = createDevice(EDT_DIRECTX9, dimension2d<s32>(800,600));
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IAnimatedMesh* arenaMesh = smgr->getMesh("Arena/arena.3ds");
IAnimatedMeshSceneNode* arena = smgr->addAnimatedMeshSceneNode(arenaMesh,0,1,vector3df(0,0,0),vector3df(-90,0,0));
arena->setMaterialFlag(EMF_LIGHTING, false);
ITexture* floor_seats = driver->getTexture("Arena/floor_se.jpg");
driver->makeColorKeyTexture(floor_seats, position2d<s32>(0,0));
arena->getMaterial(FLOOR_SEATS).Texture1 = floor_seats;
ICameraSceneNode* camera = smgr->addCameraSceneNode(0, vector3df(120,35,0), vector3df(75,35,0));
camera->addAnimator(smgr->createFlyCircleAnimator(vector3df(75,35,0), 125, 0.0005));
camera->setFOV(2);
while(device->run()) {
driver->beginScene(true, true, SColor(0,100,100,100));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Basically I need to be able to create a texture with some transparent areas and apply it to materials within my mesh. I don't want to model individual chairs. The code I'm currently testing is below.
Thanks,
-Brian
int main() {
const int FLOOR_SEATS = 12;
IrrlichtDevice *device = createDevice(EDT_DIRECTX9, dimension2d<s32>(800,600));
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IAnimatedMesh* arenaMesh = smgr->getMesh("Arena/arena.3ds");
IAnimatedMeshSceneNode* arena = smgr->addAnimatedMeshSceneNode(arenaMesh,0,1,vector3df(0,0,0),vector3df(-90,0,0));
arena->setMaterialFlag(EMF_LIGHTING, false);
ITexture* floor_seats = driver->getTexture("Arena/floor_se.jpg");
driver->makeColorKeyTexture(floor_seats, position2d<s32>(0,0));
arena->getMaterial(FLOOR_SEATS).Texture1 = floor_seats;
ICameraSceneNode* camera = smgr->addCameraSceneNode(0, vector3df(120,35,0), vector3df(75,35,0));
camera->addAnimator(smgr->createFlyCircleAnimator(vector3df(75,35,0), 125, 0.0005));
camera->setFOV(2);
while(device->run()) {
driver->beginScene(true, true, SColor(0,100,100,100));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
You first must find those material.
Use fuction getMaterialCount() and getID ( ) or getName () , to identify material which you need.
I don't know wheter irrlicht take id and names of materials automaticaly, when mesh is loaded - probably no.
In this case you must at begining to set id or names of materials.
I be waiting for other advices.
Use fuction getMaterialCount() and getID ( ) or getName () , to identify material which you need.
I don't know wheter irrlicht take id and names of materials automaticaly, when mesh is loaded - probably no.
In this case you must at begining to set id or names of materials.
I be waiting for other advices.
Hmmm
Okay,
I've been able to sort of get something working. First I made the chairs a different mesh than rest of the arena so that the material type only applies to the chairs. The problem is that there appears to be a certian camera distance / camera angle where the color key doesn't take effect. As you can see in this screenshot the chairs closest to the camera appear somewhat correctly, those further away show the color that should be transparent:
If I change the material type from EMT_TRANSPARENT_ADD_COLOR to EMT_TRANSPARENT_ALPHA_CHANNEL I am able to create chairs something closer to the effect of what I want, however as before at certian camera distances/angles the chairs simply dissappear.
Just for reference, here is a screenshot without any transparency:
My code listing is below.
Thanks,
-Brian
[/code]
I've been able to sort of get something working. First I made the chairs a different mesh than rest of the arena so that the material type only applies to the chairs. The problem is that there appears to be a certian camera distance / camera angle where the color key doesn't take effect. As you can see in this screenshot the chairs closest to the camera appear somewhat correctly, those further away show the color that should be transparent:
If I change the material type from EMT_TRANSPARENT_ADD_COLOR to EMT_TRANSPARENT_ALPHA_CHANNEL I am able to create chairs something closer to the effect of what I want, however as before at certian camera distances/angles the chairs simply dissappear.
Just for reference, here is a screenshot without any transparency:
My code listing is below.
Thanks,
-Brian
Code: Select all
int main() {
IrrlichtDevice *device = createDevice(EDT_DIRECTX9, dimension2d<s32>(800,600));
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IAnimatedMesh* arenaMesh = smgr->getMesh("Arena/arena.3ds");
IAnimatedMeshSceneNode* arena = smgr->addAnimatedMeshSceneNode(arenaMesh,0,-1,vector3df(0,0,0),vector3df(-90,0,0));
arena->setMaterialFlag(EMF_LIGHTING, false);
IAnimatedMesh* seatsMesh = smgr->getMesh("Arena/floor_seats.ms3d");
IAnimatedMeshSceneNode* seats = smgr->addAnimatedMeshSceneNode(seatsMesh);
seats->setMaterialFlag(EMF_LIGHTING, false);
ITexture* floor_seats = driver->getTexture("Arena/floor_se.jpg");
driver->makeColorKeyTexture(floor_seats, position2d<s32>(0,0));
seats->getMaterial(0).Texture1 = floor_seats;
seats->getMaterial(0).BackfaceCulling = false;
seats->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
//seats->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
ICameraSceneNode* camera = smgr->addCameraSceneNodeMaya();
camera->setFOV(2);
while(device->run()) {
driver->beginScene(true, true, SColor(0,0,0,100));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Not sure, but try this:
Code: Select all
int mcount =seats->getMaterialCount();
for(int i = 0; i < mcount-1; i++)
{
seats->getMaterial(i).BackfaceCulling = false;
seats->getMaterial(i).MaterialType = irr::video:: EMT_TRANSPARENT_ALPHA_CHANNEL);;
//seats->getMaterial(i+1).MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL ;
}
Maybe you're interested in the EMT_TRANSPARENT_ALPHA_CHANNEL bug that I found:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=16466
http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=16466