Page 1 of 1

Transparent Textures

Posted: Sun Jun 06, 2004 10:04 pm
by Trip42
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;
}

Posted: Mon Jun 07, 2004 12:08 am
by afecelis
try:
arena->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); //makes it transparent

fix it according to how you declared stuff in your code

Posted: Mon Jun 07, 2004 12:33 am
by Trip42
I've tried this, the result is the entire arena model becomes somewhat transparent. I only want one particular material to have transparency. I want the part matching the color key to be completely transparent and the other portions to be 0% transparent.

-Brian

Posted: Mon Jun 07, 2004 12:37 am
by afecelis
oh, IC, you mean like alpha transparency for fences and stuff like that?

There's a discussion somewhere in the forums on that. Try to search for it, I'll do the same.

Posted: Mon Jun 07, 2004 12:50 am
by Tyn
Check how the 2D graphics example did it.

Posted: Mon Jun 07, 2004 1:18 am
by etcaptor
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.

Hmmm

Posted: Mon Jun 07, 2004 2:58 am
by Trip42
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:

Image

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.

Image

Just for reference, here is a screenshot without any transparency:

Image

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;
}
[/code]

Posted: Mon Jun 07, 2004 5:31 am
by etcaptor
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 ;
}

Posted: Mon Jun 07, 2004 11:06 am
by slurmmunger
try to switch off mipmapping

device->getVideoDriver()->setTextureCreationFlag(irr::video::ETCF_ALWAYS_32_BIT,true);
device->getVideoDriver()->setTextureCreationFlag(irr::video::ETCF_ALWAYS_16_BIT,false);
device->getVideoDriver()->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS,false);

Fixed

Posted: Mon Jun 07, 2004 12:23 pm
by Trip42
Turning off Mip Mapping seemed to fix the problem. Thanks for everyone's help. I've included a screenshot of the corrected version.

-Brian

Image

Posted: Wed Jun 30, 2004 6:53 pm
by jox
Maybe you're interested in the EMT_TRANSPARENT_ALPHA_CHANNEL bug that I found:

http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=16466