View Full Version : Question of skybox drawing
01-23-2012, 08:40 AM
I draw the skybox first thing, with GL_DEPTH_TEST disabled. That works fine, but is probably inefficient. Drawing the skybox last may be better as huge parts of it may be occluded.
The first attempt was to move skybox to the viewing distance, the far plane in the frustum. This was not good as some parts of the skybox would come outside of the far clipping plane when I turn around. But if I move the skybox closer, it will start to occlude other geometry.
I restored the skybox to the viewing distance, and tried to disable GL_DEPTH_CLAMP, but that had no effect. The part of the skybox outside of the frustum far plane was still cut-off.
I get the feeling I am missing something basic here. Any advice would be appreciated.
01-23-2012, 10:10 AM
It seems I misunderstood the flag "GL_DEPTH_CLAMP", which should be enabled to ignore the near and far clipping planes. However, when I enable it, the skybox is still clipped.
So, I do almost exactly the following:
fShader->ModelView(view * model);
glDrawArrays(GL_TRIANGLES, 0, sizeof vertexData / sizeof (vertex));
And the result from the drawing is clipped. There is no explicit logic in the shader that discards pixels.
01-23-2012, 04:14 PM
Try glDepthRange (1, 1) - you won't need to worry about positioning your skybox with respect to the far-clipping plane (you can draw it as a 10x10x10 cube around the viewpoint if you wish) and you won't need to worry about depth clamping, depth writing, etc.
01-23-2012, 04:29 PM
Are you using glDepthFunc(GL_LEQUAL) ?
01-24-2012, 02:07 PM
Thanks, glDepthRange() in combination with glDepthFunc(GL_LEQUAL) works! I can now draw the skybox much later, where it will sometimes be occluded. It saved approximately 0.4ms. Not much, but all small changes together can add up.
01-24-2012, 05:29 PM
An alternative method, by the way, is to just place regular geometry in your map where the sky should be. This can be positioned anywhere, distance doesn't matter - you could put a low "ceiling" over a room and mark it as sky.
Skip over that geometry when drawing everything else, then draw that in a separate pass. Again, draw at it's actual position.
The trick here is to load your skybox as a cubemap; just cubemap the geometry and everything will come out perfect.
That will completely minimize any overdraw issues and should join up better than the usual method of using 6 separate quads with 6 separate textures.
You'll be freely able to rotate it (just rotate the texture matrix) if you wish, blend multiple layers, etc and it will all work a lot smoother and cleaner than drawing a box.
01-25-2012, 12:43 AM
It saved approximately 0.4ms. Not much [..]
I would definitely consider such a change a nice improvement.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.