1
\$\begingroup\$

I created a skybox in OpenGL (through LWJGL), but the only way I found to render it behind all objects was to make it very big. This leads to ugly edges between the 6 skybox planes.

Optimally, I would draw a small skybox and disable DepthTesting on all other objects, but since I want those to display in the right depth order, that isn't possible.

How can I do this?

\$\endgroup\$
5
\$\begingroup\$
glDepthRange (1, 1);

Job's a good 'un, done.


How this works:

glDepthRange() remaps depth values for the purpose of interacting with the z-buffer. Setting glDepthRange(1,1); makes every fragment, regardless of how close or far it actually is from the camera, be treated as if it was exactly at the far plane.

Remember to return it to its default glDepthRange(0,1)-setting before drawing other objects. Further details in this StackOverflow question.

\$\endgroup\$
  • 1
    \$\begingroup\$ And this allows me to make the skybox small (1x1x1) and therefore to get rid of the edges that appear with excessive upscaling. \$\endgroup\$ – mtronics Sep 21 '14 at 12:50
-1
\$\begingroup\$

the size doesn't matter so much as does the texture that you are applying to the skybox (at least so long as its bigger than your playspace, there are apps out in the wild that will help you create skybox textures with seamless edges. If you are looking to use procedural generation your skybox, you have to do some flat to spherical projection so that as you fill the pixels, they appear to to have information from the correct direction.. I was working on a skybox for a space game using perlin noise and other techniques to get nebular clouds and stars sprinkled over the skybox, so just using the 3D coordinates of the pixel on the plane wasnt enough to pass to the noise functions, I had to treat that 3D coord on the skybox plane as a direction vector, then normalize it before passing it to the noise function (essentially putting the point on the surface of a unit sphere before using it to figure out what the pixel color shoudl be)... that fixed the projection problem and eliminated all visible edges in the skybox.

There is a skybox generator for Blender, an app called SpaceScape, and a FilterForge plugin for photoshop to help with creating skyboxes... I'm sure all of them do something along the lines of what I had to do for my procedural skybox generator.

\$\endgroup\$
  • \$\begingroup\$ Thank you for your reply! For now I'll stick to static skyboxes but thanks for your advice. I'll definitely check out SpaceScape. \$\endgroup\$ – mtronics Sep 20 '14 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.