3D Quick quiestion about skyboxes [SOLVED]

Kentae

Member
Hi, I'm making a 3D space exploring game and I'm using a skybox to make it seem like you're actually in space (duh). My problem however is that in this kind of a game you'd have to be able to see objects that are quite far away, planets, asteroids, other ships and so on. These objects will eventually clip through the skybox. It's more or less fine with smaller objects like ships but it becomes very obvious when we're talking about something like planets. So I guess my question is, Is there a way to make my skybox always stay behind everything else? The only idea I've really got so far is to make the skybox absurdly large but I'm thinking there has to be a better way.
Any suggestions?
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Draw skybox to surface, draw surface with orthographic projection (d3d_set_projection_ortho), then change to perspective projection again and draw game' things.
 
R

renex

Guest
I used to turn off the depth buffer, draw skybox, and turn it back on. But it only works if your skybox is one cohesive mesh and not a bunch of smaller details.
 

Kentae

Member
Well, my skybox is just a big box,
d3d_model_block( model, -2000, -2000, -2000, 2000, 2000, 2000, 1,1 );
something like that.

EDIT: Hehey! What renex suggested worked perfectly :p And it was so simple ^^
Thanks for the help guys :)
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
hi there! how would this be accomplished in code?
surface_set_target
draw_sprite (or whatever way you draw your skybox where it should be)
surface_reset_target
d3d_set_projection_ortho (matrix_build_projection_ortho + camera_set_proj_mat in GMS2)
draw_surface
d3d_set_projection (matrix_build_projection_perspective + camera_set_proj_mat in GMS2)
 
I'm going to show you another way you can draw a skybox.

Like in your other method, turn off writing to the depth buffer while drawing the sky.

Also, have your 3d perspective and view matrices set before drawing the sky.

GML:
//GLSLES shader, (sh_sky), vertex shader:
    attribute vec3 in_Position;
    varying vec3 XYZ;
    void main(){
        gl_Position = vec4( in_Position, 1.0);
        XYZ = (vec4(in_Position.xy / vec2(gm_Matrices[MATRIX_PROJECTION][0][0],gm_Matrices[MATRIX_PROJECTION][1][1]), 1.0,0.0) * gm_Matrices[MATRIX_VIEW]).xyz;
    }
//GLSLES shader, (sh_sky), fragment shader:
    varying vec3 XYZ;
    void main(){
       vec2 UV = 0.5 + vec2( ( atan( XYZ.x, -XYZ.y ) ) * 0.15915494309, (- asin( XYZ.z/length(XYZ) ) ) * 0.31830988618 );
        gl_FragColor = texture2D( gm_BaseTexture, UV );
    }
//draw event:
    shader_set( sh_sky );
    draw_sprite_stretched(spr_sky,0,-1,-1,2,2);
    shader_reset();
spr_sky example. (on own texture page). (equirectangular projection):
 
Last edited:
Top