wrong draw order when using EMT_TRANSPARENT_ALPHA_CHANNEL

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ThePurpleAlien
Posts: 11
Joined: Fri May 15, 2009 4:20 am
Location: Canada

wrong draw order when using EMT_TRANSPARENT_ALPHA_CHANNEL

Post by ThePurpleAlien »

I've seen several references to this issue around the forums but no definitive solution and the suggestions I found didn't work for me.

I'm using a simple custom scene node very similar to tutorial 3 to draw textures in 3d space. Basically, it's my own billboard scene node. The textures are pngs with an alpha channel. I set the material type to EMT_TRANSPARENT_ALPHA_CHANNEL which makes the textures look perfect, but I then realized that the draw order is somehow messed up in that more distant objects are drawn over top of closer objects.

Using EMT_TRANSPARENT_ALPHA_CHANNEL_REF does fix this problem but of course the textures lose the smooth, anti-aliased transition from opaque to transparent which is not desirable for my game's artwork. Other suggestions like setting EMF_ZWRITE_ENABLE to true did not fix the problem.

Is there a solution to the draw order issue when using EMT_TRANSPARENT_ALPHA_CHANNEL?

I'm using opengl and irrlicht 1.6.

Cheers.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Are you sure you're setting the node's type to transparent on registerNodeForRendering? If so, irrlicht should sort it I believe. If it's being drawn over itself, then it's a much more complicated solution. If it's neither of these, you could always write your own depth sorting algorithm, which shouldn't be terribly diffiuclt. Just keep in mind, transparency does not write to the depth buffer, so if you draw something close first, and then something further back, the one further back will show since it was drawn last.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you want to enable zwrite for transparent materials you need to set the scene variable ALLOW_ZWRITE_ON_TRANSPARENT, otherwise all transparent materials are forced to zwrite off.
The thing about self-intersection from the rpevious post still holds, though, which is pretty hard to come over. For billboards this might be easier, though, as it won't be visible from all sides.
ThePurpleAlien
Posts: 11
Joined: Fri May 15, 2009 4:20 am
Location: Canada

Post by ThePurpleAlien »

That worked. Thanks.

For anyone else, here's the code to add to your scene manager:

Code: Select all

pSceneMgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
And to your scene node's material:

Code: Select all

Material.setFlag(video::EMF_ZWRITE_ENABLE, true);
Post Reply