From OpenGL Wiki
Revision as of 05:31, 20 September 2009 by Alfonse (talk | contribs) (Categorizing.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A lot of games, specially First Person Shooter (FPS) games need to render a skybox.
Typically, the skybox is just a cube. Some games render a sphere or a hemisphere but this doesn't give much of an advantage.
The texture to be applied to the cube or whatever is either made by 6 2D textures (GL_TEXTURE_2D) or a single cubemap (GL_TEXTURE_CUBE_MAP).
There should not be much of a difference in terms of performance with either GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP but at least with GL_TEXTURE_CUBE_MAP, you can bind the texture once and render all the faces in one shot.

For best performance, it is recommended to take advantage of early-z.
So, you should render everything in your scene first, then render the cubemap.
You should leave z-testing on and the depth test should be GL_LEQUAL (less or equal).
Never change the depth test while rendering a scene.
In order for the skybox to appear far away, you need to scale it sufficiently but not too much.
If you scale by too much, the zfar clip plane will cut it.
If not scaled enough, some elements of your scene will be out of the skybox.

What about transparent objects in your scene?
You should render non-transparent stuff first, then render the skybox, then render transparent stuff.
So you will miss out on the advantage of early-z because of transparent objects but this shouldn't be a problem.

You might even want to have a dynamic skybox. Perhaps some birds flying in the distance. Perhaps some clouds moving around. It is up to you.
The only important thing is that the skybox is effected by the direction in which you look at (rotation) but as you walk around, the skybox doesn't move (it doesn't translate).