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.
wrong draw order when using EMT_TRANSPARENT_ALPHA_CHANNEL
-
- Posts: 11
- Joined: Fri May 15, 2009 4:20 am
- Location: Canada
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
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.
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
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.
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.
-
- Posts: 11
- Joined: Fri May 15, 2009 4:20 am
- Location: Canada
That worked. Thanks.
For anyone else, here's the code to add to your scene manager:
And to your scene node's material:
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);
Code: Select all
Material.setFlag(video::EMF_ZWRITE_ENABLE, true);