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

Game maker 3D depth problem

lolslayer

Member
I just found out that 3D depth doesn't work anymore for me in game maker, and I don't know why. Some projects do actually still work and others don't.

If it's a game maker or a setting problem, please help me if you know anything about that, it could be because I changed the windows 8.1 preferences and those aren't valid as of yet, but they weren't before.

In the case that my code is wrong, here is my code:

Create event:
Code:
///Set variables
draw_set_colour(c_white);

d3d_start();
d3d_set_hidden(true);
d3d_set_culling(true);
draw_set_alpha_test(true);
draw_set_alpha_test_ref_value(239);
draw_set_color(c_white);
texture_set_repeat(true);
d3d_set_lighting(false);

x = 0;
y = 0;
z = 0;

zdir = 0;
dir = 0;
camx = x + lengthdir_x(100,direction);
camy = y + lengthdir_y(100,direction);
camz = 0;
spd = 0.1;

display_mouse_set(display_get_width()/2,display_get_height()/2);

model = d3d_model_create();
d3d_model_load(model, "garage.d3d");
tex = background_get_texture(tex_garage);
Step event:
Code:
if keyboard_check(ord("W")){
    x += lengthdir_x(spd,dir);
    y += lengthdir_y(spd,dir);
}
if keyboard_check(ord("S")){
    x -= lengthdir_x(spd,dir);
    y -= lengthdir_y(spd,dir);
}
if keyboard_check(ord("A")){
    x += lengthdir_x(spd,dir+90);
    y += lengthdir_y(spd,dir+90);
}
if keyboard_check(ord("D")){
    x += lengthdir_x(spd,dir-90);
    y += lengthdir_y(spd,dir-90);
}
if keyboard_check(vk_space){
    z += spd;
}
if keyboard_check(vk_control){
    z -= spd;
}

if keyboard_check(vk_escape){
    game_end();
}
Draw event:
Code:
dir -= (display_mouse_get_x()-(display_get_width()/2))/5;
zdir -= (display_mouse_get_y()-(display_get_height()/2))/2;
display_mouse_set(display_get_width()/2,display_get_height()/2);
camx = x + lengthdir_x(100,dir);
camy = y + lengthdir_y(100,dir);
camz = zdir;

d3d_set_projection_ext(x,y,z,camx,camy,z + camz,0,0,1,90,room_width/room_height,0,10000);

d3d_model_draw(model,0,0,0,tex);
The depth of the camera is 10000.

This is my result:
 
Last edited:
are you sure you haven't turned off z writing somewhere?

Also, and I could be wrong about this, but doesn't the near distance have to be something greater than zero? That could be throwing off all the depth calculations.
 
M

MishMash

Guest
Pro tip, don't set the near plane to 0 :p, set it to say 1. (or 0.1 if you need it)

The reason for this is that a hardware depth buffer is exponential, meaning more precision of data is packed closer to the camera.
For example, if your near plane is 1, and your far plane is 100. 50% of the precision will be between 1 and 2 (or something like that.)

What is actually happening here is that with a near plane of 0, the precision is actually getting infinitely packed into a very very very small region near the camera. Meaning all of these other objects do not have sufficient depth information to properly depth test.

Hope this helps :)
 

lolslayer

Member
Pro tip, don't set the near plane to 0 :p, set it to say 1. (or 0.1 if you need it)

The reason for this is that a hardware depth buffer is exponential, meaning more precision of data is packed closer to the camera.
For example, if your near plane is 1, and your far plane is 100. 50% of the precision will be between 1 and 2 (or something like that.)

What is actually happening here is that with a near plane of 0, the precision is actually getting infinitely packed into a very very very small region near the camera. Meaning all of these other objects do not have sufficient depth information to properly depth test.

Hope this helps :)
Thank you man <3
 
Top