• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Improve Height Handling For Z-Tiling [SOLVED]

Z

Zephyr Schwarzwolf

Guest
Hi GMC !

For my top-down game, I'm using a Z-Tiling shader for depth sorting. The method is the same used by Ariak in this tutorial.
For some reasons, few sprites are not tilted on the same angle (probably because "visible" images don't use all available pixels on every frames. Moreover, I set the origin on the bottom of the "visible" image, not on the bottom of the sprite itself) I don't really want to change that. My animations are more definites and it works perfectly for collisions.
Anyway, the major issue is that the alpha channel has to be piggybacked for the shader to work...
It causes a difficulty to use image_alpha, makes all tilted sprites full opaque, and limits sprites height to 255.

So, I'm searching for a system where I wouldn't be forced to use the alpha channel to encode the height of my sprites.
Code:
float top = 1.0-mod( col.b * 255.0, 2.0); // upper vertex
object_space_pos.z -= 255.0*col.a*top; // z-tilting
object_space_pos.y += col.a/10.0; // z-fighting
I would like to replace that "col.a" by another thing... But what ? Obviously, I can't just use sprite_height (It would be so great...)

I saw somewhere that it would be possible to use vertex buffers to replace the alpha technic ? But I don't know how to deal with them in that case...
Thank you in advance.
 

GMWolf

aka fel666
Forgo the shader and just build vertex buffers. It easier (long run), and more powerful.

Vertex buffers don't just work for static objects, if you need to move them, change the model matrix. If you need animation, use multiple vertex buffers; one for each frame. (iDK what Ariak was on about)
 
Z

Zephyr Schwarzwolf

Guest
Hi GMWolf ! Thank for your reply !

Do you know a good tutorial about vertex buffers which could be useful for what I want to do ?
Is the use of multiple VB on each frame harder than on a static object ?

Thank you in advance.
 
A

Ariak

Guest
You can ofc always write a custom vbuff/batching system to get around the ztilt shader drawbacks.
I designed the system specifically for my pixel art game and could thus live with all its assumptions and resulting limitations.

Here's why I didnt present a vbuff system:
  • The blogpost was already plenty long as it was. It wasnt beginner friendly to boot, and adding another major system would complicate it even further.
  • It circumvents GM's native batching by constantly changing matrices and submitting individual vbuffs which leads to unneccesary CPU overheads and tons of batch breaking. I opted for GPU > CPU.
  • ease of use is lost, as none of the native draw functions can be tilted and thus depth sorted anymore. Its back to purely flat images.
My game does use plenty of vbuffs where appropriate, e.g. all the animated reactive grass, static scenery etc. The methods do definitely not exclude each other. They work very well in tandem.

If some sprites are tilted at a different angle they are either >255px in size, or texture page cropping is enabled. The latter could lead to differing sprite_height vs actual uv coordinates, resulting in faulty image_alpha values being passed into the shader.
 
Last edited by a moderator:

GMWolf

aka fel666
  • It circumvents GM's native batching by constantly changing matrices and submitting individual vbuffs which leads to unneccesary CPU overheads and tons of batch breaking. I opted for GPU > CPU.
  • ease of use is lost, as none of the native draw functions can be tilted and thus depth sorted anymore. Its back to purely flat images
Those are actually good points I didn't fully consider.
Still I think the benefits far outweigh the costs.

As you say though, a hybrid system is probably a good way to go.

@Zephyr Schwarzwolf here is a tutorial I wrote:
It covers the basics of vertex buffers, and how they work together with vertex shaders.

would like to replace that "col.a" by another thing... But what ? Obviously, I can't just use sprite_height (It would be so great...)
You could pass in a uniform, but that would break your batches and lead to poor performance... (But if it works, it works)
 
Z

Zephyr Schwarzwolf

Guest
Hi Ariak ! Thank for your reply ! (Your tutorial helped me alot !)
You're sooo right ! I grouped my sprites in different texture pages and disable auto-cropping. They now have the same angle and the good height !
But, when I jump with my main object, the angle of the jump is still not the same (my object jumps through walls when it is in front).
I had the idea to write : image_alpha = (sprite_height + z)/255 but with this limit of 255 pixels it seems not to be a good idea...

Here are the lines of code for the jump on the z axis :
Code:
// In the Step Event :

depth = - z;

// In the Draw Event :

draw_sprite(sprite_index, image_index, x, y - z);
Thank you GMWolf ! Even if I don't use it for my depth system, it's going to be really useful for some natural effects I need ! I'm going to check that when I'm done with that damned depth system ! :D
 
Last edited by a moderator:
Z

Zephyr Schwarzwolf

Guest
Found what the problem was. I now use draw_sprite_ext insteed of draw_sprite in the Draw Event. It works perfectly !
Thank you, you two, for your good advices !
 
Top