• 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 Sprite in 3D wont show whats behind

Kahrabaa

Member
Hi.

In a 3D space, Im drawing 3 sprites with different y coordinates to place them in front of each other. The problem is the front sprite covers the back sprites even in areas that are transparent on that sprite.

Left pic is without shader. Right pic with new default shader

This only happens when I draw the sprites through a shader. (New unchanged shader)

Code:
shader_set(shader0);
    matrix_set(matrix_world,matrix_build(0,0,0,60,0,0,1,1,1));
    draw_sprite_ext(sprite_index,image_index,0,0,1,1,image_angle,image_blend,image_alpha); //Sprite 1

    matrix_set(matrix_world,matrix_build(24,-1,0,60,0,0,1,1,1)); //Shift y up a pixel
    draw_sprite_ext(sprite_index,image_index,0,0,1,1,image_angle,image_blend,image_alpha); //Sprite 2

    matrix_set(matrix_world,matrix_build(48,-2,0,60,0,0,1,1,1)); //Shift y up another pixel
    draw_sprite_ext(sprite_index,image_index,0,0,1,1,image_angle,image_blend,image_alpha); //Sprite 3
    shader_reset();
Noticed that if i invert the drawing order then the problems goes away by swapping the code for sprite 3 with sprite 1

It should draw correctly no matter the order since game objects will move around. I am trying to avoid adding all objects to a ds list to sort them then draw..
What am I doing wrong?

Code:
gpu_set_alphatestenable(1);
gpu_set_ztestenable(1);
gpu_set_zwriteenable(1);
gpu_set_cullmode(cull_noculling);
Code:
var camera=camera_get_active();
camera_set_view_mat(camera,matrix_build_lookat(x+cam3dx,y+cam3dy+250,cam3dz+500,x+cam3dx,y+cam3dy,0,0,1,0));
camera_set_proj_mat(camera,matrix_build_projection_perspective_fov(60,window_get_width()/window_get_height(),1,32000));
camera_apply(camera);

Thanks for your time
 

Joe Ellis

Member
It's cus the alpha test reference value is too low (or zero), so it doesn't discard any of the 0% alpha pixels.
You should just need to set it to something higher than zero:
GML:
gpu_set_alphatestref(0.1)
 
Top