Textures mixing and transparency in general

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
stepan1117
Posts: 10
Joined: Sun Mar 08, 2009 12:41 pm

Textures mixing and transparency in general

Post by stepan1117 »

Hello everyone,
I have a beginner's problem with transparency. The core of my problem is shown on following three figures:

Image

On the first one, there is a green box (center) between a camera (on right side) and some blue object (left side).
The second one shows a look on the blue object from that camera.
And, finally, the third one depicts the thing I need - to get a look from camera like if the green cube and everything after that cube is transparent, so I can see the visible contour of blue objects, and the rest of its parts, hidden after green box, are transparent.

I know at least three ways of how to achieve this. First is something about z-buffer priority in opengl, second is ray tracing and the last one is to mix two textures. The last one seems less complicated to me, so I tried to use that:

I've drawn a scene to texture, mix it with the background texture and draw the resulting texture. The code I used looks like this:

Code: Select all

void drawVideoTextureMix(irr::video::ITexture* rt){
	s32* rtData = (s32*)rt->lock();
	s32* ctData = (s32*)CurrentTexture->lock(true);
	irr::video::SColor transparent(255,0,0,0);

	IImage * rtImage = IrrVideoDriver->createImageFromData(rt->getColorFormat(), rt->getSize(), rtData, false);

	int pixelCount = rt->getSize().Width*rt->getSize().Height;
	int i = 0;

	for (int h = 0; h < rt->getSize().Height; h++){
		for (int w = 0; w < rt->getSize().Width; w++){
			SColor pixel = rtImage->getPixel(w,h);
			if (pixel == transparent){
				rtData[i] = ctData[i];
			}
		i++;
		}
	}

	rt->unlock();
      CurrentTexture->unlock();

    IrrVideoDriver->draw2DImage(rt, irr::core::position2d<irr::s32>(0,0),
                                    irr::core::rect<irr::s32>(0,0,desiredW,desiredH), 0, irr::video::SColor(255,255,255,255), false);
}
This one basically works, but it has one big disadvantage - it is reeeeally slow (I get 10-12 FPS) due to lock() function. So my question is - is there any other way how to mix two textures, or any other better approaches to my problem?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It seems that you could render the green box with color writes disabled (write only the depth to the zbuffer), and then render the blue sphere with color writes enabled.

You should be able to do this with a call like...

Code: Select all

cube->setMaterialFlag(EMF_COLOR_MASK, false);
Travis
stepan1117
Posts: 10
Joined: Sun Mar 08, 2009 12:41 pm

Post by stepan1117 »

Hi, thanks for your answer, I'll try it as soon as possible. One problem I have now is that I cannot see the EMF_COLOR_MASK flag in Irrlicht 1.5 release. Do I have to use the current svn ver.?

Stepan
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, color mask will be available only in Irrlicht 1.6, you can use it right now from SVN/trunk.
stepan1117
Posts: 10
Joined: Sun Mar 08, 2009 12:41 pm

Post by stepan1117 »

Hi, it really works under current 1.6 svn, thanks very much for your help!
Post Reply