• 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!

SOLVED How do I use Vertex Buffers with a Depth Sorting System?

Hello,

GMS 2.3.1
I'm using this depth sorting system: I am trying ot make it work with this asset (which utilizes vertex buffers): I'll be honest I don't know much about vertex buffers so I apolagies if I say anything incorrectly in regards to vertex buffers.

If I try and use this asset with the depth sorter, it always remains infront of eveything, no depth when trying ot move obj_player behind the grass. The asset works like a charm with my game when I avoid this depth system, and revert to the usual depth=-y;, however I am inclined to carry on using this depth sorting system in order to avoid any issues in the future such as flickering (which I assume happens when two sprites are on the same y value).


This is the code for the depth sorter incase anyone wants a closer look at it.:
Specifically the Draw event of the object "depthsorter".
Code:
// MAKE SURE TO UNTICK VISIBLE FOR ALL OBJECTS BEING SORTED (CHILDREN OF THIS)

var inst_num = instance_number(par_depthobject);
var dgrid = ds_depthgrid;


if ds_grid_height(dgrid) != inst_num {
    ds_grid_resize(dgrid, 2, inst_num);
}

// add instances to grid
var yy = 0; with (par_depthobject) {
    dgrid[# 0, yy] = id;
    dgrid[# 1, yy]= y
    yy += 1;
}

// Sort grid in acsending order
ds_grid_sort(dgrid, 1, true);

// loop through grid and draw instances

var inst; yy = 0; repeat(inst_num) {
    // pull current id
    inst = dgrid[# 0, yy];
    // draw
    with (inst) {
        event_perform(ev_draw, 0);
    }
    
    yy += 1;

}
I've tried using debug code that came with the asset such as gpu_set_ztestenable(true), as well as doing the obvious: making obj_vertexgrass a child of par_depthobject.
I'm unsure how to add vertex buffers / grass from the asset to to the sorter. I can only assume that they appear in the room layer "Instances" because how else would depth=-y work.

However (correct me if I'm wrong) these "vertex buffers" or "grass" clearly don't have par_depthobject as a parent since they're not being ordered, they must be being created without a parent, so unless I can set the parent of each grass vertex in the shader, I may need to find a way to make the depth sorter sort everything in the Instance layer, and not be restricted to children of the par_depthobject. The easy way out is to not use the depth sorter and just simply stick to depth=-y; but I feel like thats also the worst way to do it.

I apolagies if this one is a head scratcher, I've tried to break it down as much as possible. Help would be very much appreciated.
 
I spoke with the asset developer, and after I got an understanding of what vertex buffers are, he helped me come to the conlusion that I should not use the depth sorter.
I've gone back to the depth =-y; method. Should I experience flickering due to two sprites having a similar x axis and the exact same y axis (hence why I used the depth sorter in the first place), I'll add an if statement in the parent object that would lower the obj_players depth by 1 to tackle that.

Hope this comes in handy for anyone with a similar issue in the future.
 
Top