Force an image to render on top of another *regardless* of code excution order.

I have this awkward problem I’ve been trying to solve, and I can’t figure out how.

Basically I use LinebyLine rendering on my tiled map, in a nutshell, this allows the player/entities to be rendered either in front or behind an object depending on his Y location. The problem here is I have to also render my blood on the ground behind the player at all times no matter what, but the blood has to be rendered on top of the map at all times no matter what. (Thus rendering over the player as well) What I need is a way to always render the blood on top of the entire map as a whole, yet not on top of the player, who code-wise is rendered in the middle of rendering the maps depending on his Y location (that are under the blood rendering execution).

So basically, the rendering order goes like this:

Objects under the player -> Entity/Player -> Objects over the player -> blood.
But blood needs to be both under “Entity/Player” and over “Objects over the player” at the same time.

I can’t just put the blood behind the player, because then it wont render on anything “over the player”. Basically, the blood must render after the player and the entire map does but the player itself needs to be rendering over the blood. Is there any trick to make an image render on top of another specific image regardless of the order the render methods are called?

I tried googling for a solution, but all I keep finding is ultra-beginner stuff like “rendering 2 overlapping images” by the obvious method, draw one, then draw the other one line down. So I’m kinda stumped. I feel like there’s a simple way to do this I’m not fully grasping. :stuck_out_tongue:

glEnable(GL_DEPTH_TEST);

Did you try it?
Even without having a 3D scene depth testing can be useful.

cheat and render the blood twice. have several similar sounding situations in my game where i render them under 1 layer, then over another layer and it seems ok.

It seems like you’d want to make the blood part of the line-by-line rendering sequence. But, no matter how this problem is looked at, it seems like you’d have to redo the way all entities in the project is drawn. I think that you may have to consider splitting up your drawing layers differently.

  • Ground
  • Ground [Blood]
  • Buildings/Objects (behind player)
  • Buildings/Objects [Blood] (behind player)
  • NPC’s (behind player)
  • Player
  • NPC’s (in front of player)
  • Buildings/Objects (in front of player)
  • Buildings/Objects [Blood] (in front of player)

Yes, it is a lot. However, it’ll allow you to fine tune the Y-axis layered draw cycle to the letter while (hopefully) keeping your speed and draw calls to a minimum. Other than that, you are going to have to draw overlaps twice in order to compensate and that may ruin performance. I’d just redo the graphic layers so it’ll prevent the processor from doing double work. This problem will only become worse if you want more layered effects (like acid splatters, oil splatters, electricity, lighting, etc.)

Building your draw layer system from the start to handle this will allow you to add things easier in the future. Especially since you want to make it easier for people to make custom content.

Actually your example is very close to how I am setup already. Just take out the additional blood layers and throw in the clouds/lighting layers on top. :stuck_out_tongue:

The problem though is there’s situations where blood taking up the same tile space has to exist in a situation where it’s both infront and behind the player at the same time, it’s a bit confusing to explain.

Basically, blood on the ground is drawn to a 32x32 tile. The player can either be above or below that tile, but there’s situations where the player is standing “over” an object in that 32x32 space or “under” the same object if he’s on the other side. Thus, in a situation where the player is standing below the object, but still in the 32x32 space, the entire blood tile would have to exist under the player, but on top of the object. But, if the player is behind the object in that space, the entire blood tile (even whats above the players head, and behind him on the ground) would have to exist on the object he’s behind and behind him, without rendering on top of him as well (but still rendering on the object he’s behind)… :confused:

One solution might be to simply toss out the blood tiles all together and go back to my old system where particles just exist on the ground as themselves, and then sort all those particles by Y values alongside my entities. But I think that would cause another problem where blood ends up spawning behind objects when they should spawn on them.

EDIT: I just realized my whole explanation was needlessly confusing; Basically I just need the player to render overtop the blood, regardless that the blood’s render call is after the player is. One idea would be to simply not render the blood if the player’s X/Y coordinates match, but that would cause the blood to vanish/appear unless I use a ton of resources to do pixel-by-pixel checks.

Hmmm… Does the blood have to render on the player itself?

The only way I can see that you’ll have to draw extra layers of blood is if the blood can pool up into piles. But even if that is the case, you still only have two options, to change the layering system or to draw the overlapping offenders again. Art doesn’t leave that much wiggle room like programming does. It seems to me like your blood has to be part of your map rendering sequence. Maybe you can experiment with drawing the player sprite’s feet last (if visible) on the screen. If anything is overlapping the feet, redraw those elements. Quite complicated, but it may work…

I can’t really think of a scenario in where the blood will have to be drawn between the player and the object it is on. If that is the case, you’ll have to handle blood on sprites differently. Worst case, you’ll probably eat a bit of clipping issues which is kind of forgivable in this isometric style you’ve chosen.

I’d probably make blood render when the buildings and objects do, instantly after those objects are drawn. For me, it makes sense that if you are rendering blood onto the objects, the blood should be rendered at the same time. Your rendering may be close, but if it isn’t exact you’ll have to just draw overlapping offenders again (or set up a voxel system :stuck_out_tongue: ).

I think I’m just going to re-tackle the problem again down the road, the main reason for the LineByLine rendering was to allow a player to be able to be both behind or in front of an object based on the Y axis

for example, this is as close as the player/entity could get to the bar from the top side with my old (now current again) system. This system completely eliminates all my problems because the player is simple drawn above the objects/blood, but he can never go “behind” smaller objects, like this bar. He can only go behind objects on the layers above him, that are non-interactive (and do not get blood splatters either)
http://sixtygig.com/junk/InDev-2014-04-15-6.png
(and on the other side)
http://sixtygig.com/junk/InDev-2014-04-16-1.png

The new system, the player could get behind the bar, but the blood problem discussed in this post becomes an issue because of the layering issue:
http://sixtygig.com/junk/InDev-2014-04-15-7.png

I think this may be one of those cases where I just have to decide whats more important, the cool blood splatters ( https://www.youtube.com/watch?v=tVO9fJ3SJuc ) or the ability to “walk behind” the smaller objects like barrels, the bar, etc, that only use single 32x32 tiles.

If you watch the video, I think you’d probably agree the blood is more important. I think so anyway. It’s not like the player can’t get behind objects at all, he can still go behind larger objects like lightpoles, buildings, trees, etc. He just cant go behind small objects.

Yeah, I’d agree your blood is more important. I will respect your decision to handle it later, but when it comes to art, the best solution is either to overlap or split things up into sections… there is no in-between. I’ll go back into lurking now :slight_smile:

oh yeah, I totally agree.

It’s funny though, your suggestion is almost exactly how I do things now anyway. Even without the line by line rendering:

  • Terrain Layer
  • Object Layer
  • Building Layer
  • Blood Layer
  • Player/entities layer (Sorted by Y, so they properly overlap)
  • Roof Layer
  • Overhead layer (IE: Overhead lamps, tops of lightpoles, tops of trees, etc etc)
  • Lighting Layer
  • Sky Layer (Just cloud shadows really)

The layering may seem a little out of order at the end there, but the overhead is “above” the roof layer so it can be used to place things on top of the roof. :slight_smile:

So it sounds like we’re both thinking the same way, just the Line-by-Line method that allowed me to render the entities and objects all mixed together just botches up the blood system. /sigh.

did you try stencil testing?