Depth sorting

edited April 2015 in General discussions
Hi,
I just came across this blog http://davidfahr.com/?page_id=128 where the guy implements the depth sorting using depth map. Also this blog does describe the similar/same thing http://toxicdump.org/blog/view/8/Pixel-perfect-depth-sorting-using-a-depth-buffer-in-25D.

I do understand the basic concept but I would like the know inner details of it.

For instance, what they mean by the world-space depth map? Then, how to composition works? When I place for instance 2 castle on the same map. One is at the top, another beneath it. I was getting impression that the final depth map generated for the scene must be "continuous" so the 2 castles must somehow be incorporated to the final depth map. Or maybe I'm wrong :)

So does anyone know the details of these thechnique? Maybe I'm dumb but I cannot understand from the blog posts how it works.

Thank You

Comments

  • edited April 2015
    So I found some more info about this technique http://infictitious.blogspot.sk/2012/09/25d-xna-rpg-engine-some-technical.html .

    The world-space height map means, that the pixels in the bottom of the 3D object (bottom in the world scene, that is for instance Z=0) are black and at some maximum top (for instance Z=3) are all white. This depth map should have all the sprites.

    Then we've got that fragment shader that will output the depth for the given fragment from the depth texture (outputting depth in the fragment shader could be slow, because no early Z rejection would be possible). Also we need to sort the sprites before rendering if we're using transparency (but this is done in orx AFAIK).

    So when two sprites are met, the depth value (of each fragment) of both are "compared" and the one that should be "before" the other is drawn.

    I would definitely try it but not now, because it could solve the problem of tiling the big sprites when they're occupying multiple tiles (for instance some car wreckage).
  • edited April 2015
    Hi Trigve,

    Your last link (the one in your second post), isn't working for me.

    If you end up trying this, I'm curious to know about the results. :)
  • edited April 2015
    Thanks, the link is fixed now.

    I'll let you know (but probably not too soon) how it goes.
  • edited May 2015
    Here I am,
    we good new and bad news.

    First the good one. I've tried to it implement it and it was working kind of good. I mean the general principle is working right, but in our case, where we have composite sprites, the pixel on the "seams" between the sprite parts are "blinking" and it is looking ugly. But otherwise it is good technique.

    Now, the bad news. After some math etc. I've found out that we would need insane amounts of sprites for our game (this hasn't nothing to do with depth sorting), around 30 000. So after the discussion we're moving to the 3D engine :-/ It's a shame because I enjoyed the orx engine and our render sprites quality (with blender cycles and lot of custom materials) is way higher than the real-time rendered 3D with all the whistles.

    I just want to thanks all the people here and especially iarwain for help. The community here isn't large but the passion here is great.

    So wishing all the best luck for you.
  • edited May 2015
    Hi Trigve, sorry it didn't work out for your current project. Hopefully Orx will suit your next 2D project.

    It is a good little community here. We're like an undiscovered oasis on the edge of the galaxy.
  • edited May 2015
    Hi Trigve, I guess if you need ~30000 sprites, your game is "too 3D" to be represented in 2.5D. Hope to see you around for another game!

    BTW:
    iarwain wrote:
    If you end up trying this, I'm curious to know about the results. :)
    Is that really possible to implement in Orx? I previously had the impression that the Z-buffer is disabled in Orx. Do you suggest that one could imitate a Z-buffer using some tricks involving render-to-texture?
  • edited May 2015
    Hi Trigve, sorry it didn't work out for your current project. Hopefully Orx will suit your next 2D project.

    It is a good little community here. We're like an undiscovered oasis on the edge of the galaxy.
    No problem with that, experience gained :) Wish the community all the best.
    Hi Trigve, I guess if you need ~30000 sprites, your game is "too 3D" to be represented in 2.5D. Hope to see you around for another game!
    Yeah, but we wanted to go for 2D because of this "2D feeling" and because of the quality of the pre-rendered sprites. I've got some plans for the 2D game but would need to finish this one as first.
    Is that really possible to implement in Orx? I previously had the impression that the Z-buffer is disabled in Orx. Do you suggest that one could imitate a Z-buffer using some tricks involving render-to-texture?
    It is disabled by default but you can enable it in the .ini. The case in which we had used this depth sorting is special because of isometric nature. In isometric, the thing which is "more up" is usually behind something. And our depth map takes this in the assumption.

    I don't think I understand your last question. Depth sorting is using Z-buffer actually (or maybe you're pointing to the stuff I wrote about sorting the sprites for each frame mention in another post?)
  • edited May 2015
    Hi Trigve,

    Sorry to hear you leaving us, but it definitely makes a lot of sense given your constraints.

    I'm sorry I got quite a lot delayed for the "list of structures" feature, I did half of it and then improved it a few weeks later, but I still need to finish the last part. Lately I haven't had as much time to work on orx as I'd have liked, mostly due to starting a new game project.

    Hopefully we'll see you again in the future for another 2D game and I wish you the best for your current project! Out of curiosity, which 3D engine did you pick?
  • edited May 2015
    iarwain wrote:
    Hi Trigve,
    I'm sorry I got quite a lot delayed for the "list of structures" feature, I did half of it and then improved it a few weeks later, but I still need to finish the last part. Lately I haven't had as much time to work on orx as I'd have liked, mostly due to starting a new game project.
    That's OK, we all know that there is never enough time ;)
    Hopefully we'll see you again in the future for another 2D game and I wish you the best for your current project! Out of curiosity, which 3D engine did you pick?
    Yeah, I've got some plans for one 2D game (I have started that planned project around 7 years ago, as full 3D, then moving, it to isometric 3D and finally to 2D but it is on hold for now).

    The engine I picked? That would be very funny answer because it will look like I have some schizophrenia disorder :D

    We've picked unity3D 5 :)

    I've tested around 3-4 3D engines, and was sure I was going with unreal engine, but after lot of testing, I just gave up because it is too slow on my machine to work with, has problem importing some special skeletal animation (which are crucial for our project) and couldn't be workaround easily. Also the build size for simple scene was around 100 MB which also was kind of weird. I like that is is using C++ and was kind of disappointed that I couldn't use it.

    The unity was the last engine I would return to, but the animation was working right (with some minor workarounds) and I has some experience with it.

    The crucial fact is that I will be using native DLLs for the all the gameplay. I've made some test with marshalling between C# and C++ and is working great. This is because I have a solid code base that I wouldn't like to rewrite in C# (and don't like C# personally, I feel like lot of constrained - which is opposite of C++), not mentioning that I'm using stuff that would be impossible (or at least hard) to do in C# (stateful coroutines). So I'm back there.

    Also I would need to workaround unity problems I have written in my very first post in this forum (have solution for most of them).

    I will post some updates on our game and maybe also publish what we have achieved using orx.

    I still think that orx is superb to unity when we're talking about 2D stuff.
  • edited May 2015
    Trigve wrote:
    I don't think I understand your last question. Depth sorting is using Z-buffer actually (or maybe you're pointing to the stuff I wrote about sorting the sprites for each frame mention in another post?)
    Thanks for the explanation, the last question was about a possible workaround for the first question, which you've answered. I was speculating maybe you could simulate a depth-buffer using offscreen rendering, but that's irrelevant since one doesn't need the workaround in the first place.
  • edited May 2015
    Thanks for the details, Trigve!

    I know other devs who had to let Unreal on the side and go with Unity for the same reason of not being able to run it on their machines.

    Best of luck with Unity and your project. Looking forward to seeing more about it. :)
Sign In or Register to comment.