CoolDotty / Shader-Stacker

The GPU accelerated version of Sprite Stacking. A top-down 2.5D trick for the Godot Engine.
https://dotty.cool/Shader-Stacker/
Mozilla Public License 2.0
56 stars 7 forks source link

Keeping depth levels with automatic z-sorting #4

Closed Chownie closed 3 years ago

Chownie commented 3 years ago

image

I'm having some issues with z-sorting and keeping the correct sprites in the foreground, how can I position a moving sprite to keep it visible appropriately?

How does centre interact with automatic z-sorting?

CoolDotty commented 3 years ago

Right now center has no effect on the z-sorting. You can see how it's calculate on line 42 of StackedSprite.tscn

So I'm guessing since it has no effect and that the floor and chest are in the same spot, it's up to the node order to decide who goes on.

Maybe try multiplying center by the sign of global_position.rotated(cam_rot).y and add it to z_index?

Chownie commented 3 years ago

Gave that a go and it hasn't reordered the chest, plus I'm seeing some odd flickering between the walls now, where sometimes it seems like the internal faces are z-fighting: image

Apologies, I know that's a not a great screenshot example, my trig isn't great but I'll continue to fiddle with this and see if I can work out how to create something that feels right.

Is it idiomatic to do layering a different way? I had assumed that given the z_indexes are being manually set that I'd have to mess with that to set the draw order, how do you currently create holes/pits/etc?

CoolDotty commented 3 years ago

Hmm. So the OG sets a z-index relative to the middle point of the bottom layer. The important part is it orders so sprites near the top of the screen are rendered before sprites near the bottom.

The idea with center was you keep 99% of things on default 0 so they're sitting on the floor with their bottom layer. Then center would be an escape hatch you would set to the highest layer, making a hole effect for a crack in the ground or something.

What center values are you using for your objects?

Chownie commented 3 years ago

The values are a little bit strange maybe. I had assumed differently with regard to center, so I have a bunch of sprites for objects at 0, then the floor tiles at 16 and objects hanging above at -16

CoolDotty commented 3 years ago

Hmm, yeah. So in terms of ordering correctly, you want your floor to be at 0. For everything else, you want their node position to be where the would sit if they were level with the floor, and then use center to "raise" or "lower" the object above or below the floor.

CoolDotty commented 3 years ago

I've renamed center -> height in the latest update. Hopefully that clears up the confusion for the future!