PDA

View Full Version : How to use the depth buffer for sprites?



Neo
08-28-2013, 03:01 PM
Hello everybody.
I'm new to ClanLib and at first, I would like to say hello to this community and that this lib is really great and it gives me so much more options for effects with shaders etc.
For my GameEngine I used HGE (http://hge.relishgames.com/) before, but I want to change it complete to ClanLib.

Much to my regret ClanLib does not support z-ordering for Sprites, so I wrote my on Helper to sort the Sprites from back to front.
The problem now is, that I render a tilemap with 3 diffrent tilesets and each tile can have a diffrent depth value, wich is calculated from the Y-Position and a priority value (1-10). I also support dynamic objects, wich are sorted against this list.

Because of the texture change, the batcher renders only about two or three tiles in one batch and my frames drop to 30 FPs with 900+ tiles.

I never had this performance problems with HGE, because it supports z-ordering using the depth buffer of DirectX. This allows me to render the tiles for each tileset in one batch and the depth buffer renders the tiles in the correct order.

I see that the canvas class in ClanLib 3.0 support the command "clear_depth", so is there a way to use the depth buffer with sprites or images?
Or is there a specific part in the code of ClanLib where I can set the z-value manually?

Hope someone can help me with this.

Update:
Actually I'm using only the opengl renderer because of future Linux compatibility.
Maybe it makes things easier to edit?

Thanks in advance!

Jamesfredette
08-29-2013, 09:04 AM
Welcome to the forum,
I hope your issues would soon be able to be resolved by the mods.
Have a great time out here.

Neo
08-29-2013, 10:53 AM
Thank you, Jamesfredette.

Update:
Actually I'm using only the opengl renderer because of future Linux compatibility.
Maybe it makes things easier to edit?

Thanks :)

Judas
08-29-2013, 12:29 PM
Looking at the reference docs for Sprite, it seems that you can only use X,Y positions when drawing them currently. I am pretty certain that at some point in the past there was also a Z parameter, which probably was intended to be used together with the Canvas::clear_depth function you've already found.

Personally I've always found depth buffer sorting rather useless for 2D because the method cannot support more than on/off transparency. Using compute shaders and DX11 hardware it is possible to remove this limitation, but such a patch would never be accepted due to all the 1865 hardware fans out there. :cry:

All that said, I'm not sure why the performance drops so badly as you describe. The batcher in ClanLib can use up to 4 different textures in the same batch, which should keep all your sprite sets within a single batch. How are you loading your sprite sets today, and how are you doing the sorting?

Neo
09-01-2013, 09:15 AM
Thank you Judas!

Your post helped me a lot for another view.
My problem was that I used a modified version of the HSV Batcher (examples) with just one texture instead of the mentioned for textures.
I didn't know that ClanLib used a own shader for sprite rendering, so I disabled my modified batcher and use the standard one.
This gives me up to 300+ frames!

Thank yo so much for your help :hat: