Jump to content


Photo

3D Depth Ordering


  • Please log in to reply
6 replies to this topic

#1 ReDevilINC

ReDevilINC

    GMC Member

  • GMC Member
  • 12 posts
  • Version:GM:Studio

Posted 08 December 2011 - 07:47 AM

Hello GMC. I am trying to make a 3D game. I have a problem with depth ordering... I try this code in Step Event:

depth = (room_width-x)+(room_height-y)
It works, but not from different view points

Posted Image

How I can fix that? I will give credits in my game :happy:
  • 0

#2 ynspyred

ynspyred

    GMC Member

  • New Member
  • 328 posts

Posted 08 December 2011 - 03:25 PM

A common approach is to set the depth using the distance from the camera position, so far away objects are drawn first, then nearer ones, so blending will work correctly.
var cam_pos_x;
var cam_pos_y;
var cam_pos_z;
// set these variables to the position of the camera

var cam_dist_sq;
cam_dist_sq = (cam_pos_x - x) * (cam_pos_x - x) + (cam_pos_y - y) * (cam_pos_y - y) + (cam_pos_z - z) * (cam_pos_z - z);

depth = cam_dist;
// or depth = round(cam_dist); or something


  • 0

#3 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 620 posts
  • Version:GM8.1

Posted 09 December 2011 - 03:24 AM

If you're using GM8.1.139, you can fake the depth ordering:

d3d_set_zwriteenable(false);
//glowing object draw code
d3d_set_zwriteenable(true);
It really only works on objects that don't have a clearly defined shape, like the one in the screenshot, because it orders the faces incorrectly but removes the artifacts.

Edited by jsorgeagames, 09 December 2011 - 03:24 AM.

  • 0

#4 ean

ean

    GMC Member

  • New Member
  • 190 posts
  • Version:GM8

Posted 09 December 2011 - 09:24 PM

If you're using GM8.1.139, you can fake the depth ordering:

d3d_set_zwriteenable(false);
//glowing object draw code
d3d_set_zwriteenable(true);
It really only works on objects that don't have a clearly defined shape, like the one in the screenshot, because it orders the faces incorrectly but removes the artifacts.


No such function exists, I checked to make sure I have the latest update in the stable channel too. Am I supposed to update to the latest unstable version? (I'm not going to if I do.) In the list of updates it says D3D_ZWRITEENABLE but that doesn't do anything.

Edited by ean, 09 December 2011 - 09:27 PM.

  • 0

#5 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14384 posts
  • Version:GM:Studio

Posted 09 December 2011 - 11:51 PM

A common approach is to set the depth using the distance from the camera position, so far away objects are drawn first, then nearer ones, so blending will work correctly.

var cam_pos_x;
var cam_pos_y;
var cam_pos_z;
// set these variables to the position of the camera

var cam_dist_sq;
cam_dist_sq = (cam_pos_x - x) * (cam_pos_x - x) + (cam_pos_y - y) * (cam_pos_y - y) + (cam_pos_z - z) * (cam_pos_z - z);

depth = cam_dist;
// or depth = round(cam_dist); or something


If you are walking on flat terrain, depth = point_distance(x,y,cam.x,cam.y) should be enough. or just using your formula here without the z, probably faster to use the math instead of the function call.


I place the code in an alarm that is randomized when the 3d object is created

on create
alarm[0] = random(room_speed)+1;

and I only do it 4 times a second
on alarm0
alarm[0] = room_speed/4;
depth = point_distance(x,y,cam.x,cam.y)

that way not all are doing it at the same time and not every step, and this allows for more 3d objects in the room.
  • 0

#6 jsorgeagames

jsorgeagames

    GMC Member

  • GMC Member
  • 620 posts
  • Version:GM8.1

Posted 10 December 2011 - 07:03 AM

No such function exists, I checked to make sure I have the latest update in the stable channel too. Am I supposed to update to the latest unstable version? (I'm not going to if I do.) In the list of updates it says D3D_ZWRITEENABLE but that doesn't do anything.

I do know that the function is not listed in the help file. I am on the beta channel so it might be an unstable-update-only function.

I would just depth-order everything by distance to the camera, and worry about the object's depth issues with itself later.
  • 0

#7 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1587 posts
  • Version:GM8.1

Posted 11 December 2011 - 01:02 AM

Keep a list of all transparent objects. Sort and draw them after all the other objects (I recommend quicksort or mergesort). To quickly solve the self-depth issue (can be done in-model for your case, but this is faster), consider rotating your glowing object to face the camera.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users