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

GameMaker Require help with implementing silhouette effect with depth sorting system

S

ShuDiZo

Guest
First of all, thank you for visiting and reading this request. The issue i'm currently trying to fix is the silhouette system as it only draws the effect while it is behind another instance that is not part of the list; instances not using the depth system.

- All instances using the depth system has obj_parent_depth as an ancestor
- If using the tradition depth =-y system, the silhouette will still draw as if the player is underneath the instance.

----- DEPTH SYSTEM -----

//Check if grid exists
if(ds_exists(ds_depthgrid, ds_type_grid)){

//make ds_depthgrid local and accessable to our instances (all children of depth parent)
var depthgrid = ds_depthgrid;

//get the number of instances (number of children)
var instNum = instance_number(obj_parent_depth);

//resize the grid to the number of instances/children
ds_grid_resize(depthgrid, 2, instNum);

//declare a local variable we will increment with each loop when adding children to grid
var yy = 0;

//add all the instances/children to the grid, and their corresponding y value
with(obj_parent_depth){
depthgrid[# 0,yy] = id;
depthgrid[# 1,yy] = y;
yy += 1;
}

//sort the grid in ascending order (lowest Y will be at the top)
ds_grid_sort(ds_depthgrid, 1, true);

//use repeat to loop through the grid, starting at height = 0, drawing the instance,
//and then incrementing yy for the next loop, to draw the next instance in the grid
yy = 0; repeat(instNum){
var instanceID = ds_depthgrid[# 0, yy];
with(instanceID){ draw_self(); }
yy+=1;
}

//clear all cells of the grid to 0
ds_grid_clear(ds_depthgrid, 0);
}


----- SILHOUETTE DRAW STEP -----
gpu_set_blendenable(false);
gpu_set_colorwriteenable(false, false, false, true);
var cam = view_camera[0];
var cx = camera_get_view_x(cam);
var cy = camera_get_view_y(cam);
var w = camera_get_view_width(cam);
var h = camera_get_view_height(cam);

draw_set_alpha(0);
draw_rectangle(cx, cy, cx+w, cy+h, false);
draw_set_alpha(1);

gpu_set_colorwriteenable(true, true, true, true);
gpu_set_blendenable(true);


----- SILHOUETTE DRAW END STEP -----

gpu_set_blendmode_ext(bm_dest_alpha, bm_inv_dest_alpha);
gpu_set_alphatestenable(true);

with (obj_cb01){
gpu_set_fog(true, c_fuchsia,0, 1);
draw_self();
}

gpu_set_fog(false,c_white,0,0);
gpu_set_alphatestenable(false);
gpu_set_blendmode(bm_normal);
 
Last edited by a moderator:
Hi. I don't have GMS2 so I can't test this for myself. But since you can set the depth comparison mode for the zbuffer, you should be able to use this in order to easily draw silhouettes:

https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/drawing/gpu/gpu_set_zfunc.html

the idea would be to draw the silhouette only if it is greater than what is already on the depth buffer (i.e. farther away from the camera).

------------------------------

But in regards to your script. Can you provide a short outline of the logical steps you are *trying* to take? It can be difficult to extract that information by looking at code, especially if the code doesn't work as intended.
 
S

ShuDiZo

Guest
Hi. I don't have GMS2 so I can't test this for myself. But since you can set the depth comparison mode for the zbuffer, you should be able to use this in order to easily draw silhouettes:

https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/drawing/gpu/gpu_set_zfunc.html

the idea would be to draw the silhouette only if it is greater than what is already on the depth buffer (i.e. farther away from the camera).

------------------------------

But in regards to your script. Can you provide a short outline of the logical steps you are *trying* to take? It can be difficult to extract that information by looking at code, especially if the code doesn't work as intended.
I've tried applying the zbuffer you mentioned, but to no extent did it solve the problem. The problem is that instances such like trees and pillars are drawn as the same depth as the player, and then organised by the depth sorting system all have a silhouette mask. The silhouette system is using the same object as the depth sorting system.
 
Top