• 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 [Solved] 3D Z Testing doesn't work GMS2

Anixias

Member
I am using vertex buffers to create and store primitives and models, but whenever I use vertex_submit, the entire vertex buffer is rendered at a single depth, in the order I submit them. This means that nothing can really phase-through anything else. It's not too hard to set objects at the correct depth, but the individual vertices of two separate vertex buffers do not have world-depth. The vertex_buffer itself has one depth. Everything within the vertex buffer uses Z Testing properly, but not multiple separate vertex buffers. My only solution would be to render everything into one vertex buffer, but then, how would textures work?

Here, all of these spheres have a z of 0, and a depth of 10:


EDIT:
Using
depth = point_distance_3d(x,y,z,obj_world.camx,obj_world.camy,obj_world.camz);
on the spheres definitely helps, however, the spheres do not actually collide with each other. I need them to actually go through each other.
 
Last edited:

MilesThatch

Member
Are you using actual 3D functions with a 3D camera or are you working in just 2D mode and only the spheres are are made from vertices? Cuz with the latter the fact that you made the sphere from vertices won't change the fact that it's rendered as a flat image.

Depth deals with determining if an object is drawn on top or below another object. Sure saying "What is on top and what is below" sounds like what you need but it's not. it doesn't deal with actual XYZ coordinates of vertices which is how you get objects to go through each other. The vertice coordinates of one object literally have be inside the other object. What depth does is just determine which pixels get drawn on top of which while disregarding the actual XYZ location of those vertices. If anything using depth breaks the normal way of drawing your 3D objects which is by using the dedicated camera function:

matrix_build_projection_perspective_fov(fov_y, aspect, znear, zfar);

This function is responsible for drawing your objects in 3D. I've responded to your comment in the video with a little demonstration straight from the project I used in the "Import 3D OBJ objects tutorial"

What you need is in the draw event where you draw your matrix that you've built with all the vertices, normals and UV coordinates:

var mat = matrix_build( x, y, -100, 0, 180, 0, 0.5, 0.5, 0.5 );
 
Last edited:

Anixias

Member
Hi, thanks for the reply. Yes, I am using those 3D functions and I am using the world matrix to transform my vertex_submit calls.
Code:
projection_matrix = matrix_build_projection_perspective_fov(fov, aspect, znear, zfar);
camera_set_proj_mat(view_camera[0], projection_matrix);
This is called in the Step event. Should I move it to the Draw event?

Here is the whole Step event for the obj_world object:
Code:
camx = tx;
camy = ty + magnitude * dcos(vAngle);
camz = tz + magnitude * dsin(vAngle);
var matrix = matrix_build_lookat(camx, camy, camz, tx, ty, tz, 0, 0, 1);
camera_set_view_mat(view_camera[0], matrix);

projection_matrix = matrix_build_projection_perspective_fov(fov, aspect, znear, zfar);
camera_set_proj_mat(view_camera[0], projection_matrix);
This is just camera positioning and setting the matrices.

I should note that I am not using camera_set_update_script();. I am just completely not using it. I don't see why I should, since the script can't access instance variables.

Thank you for helping me out, man.

EDIT:
Here is a download link to my project: https://www.mediafire.com/?xje1jxsm3p6570v
 
Last edited:

TheSnidr

Heavy metal viking dentist
GMC Elder
Had a brief look at your project, noticed you're using display_reset. I've had trouble previously where this function permanently seems to turn the z-buffer off, that might be what's causing your issues. Try removing it.
 
L

Lahssoo

Guest
Had a brief look at your project, noticed you're using display_reset. I've had trouble previously where this function permanently seems to turn the z-buffer off, that might be what's causing your issues. Try removing it.
Indeed, or you can gpu_set_zwriteenable(), gpu_set_ztestenable() and gpu_set_cullmode() on every step. Mike said the bug was known somewhere (can't find the post), so we should have a fix sometime down the line.
 
K

Kenjiro

Guest
Hibba dibba da dibba do.
 
Last edited by a moderator:
Top