Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Question of skybox drawing

  1. #1
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    212

    Question of skybox drawing

    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.

  2. #2
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    212

    Re: Question of skybox drawing

    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:
    Code :
    	glBindVertexArray(fVao);
    	fShader->EnableProgram();
    	fShader->Projection(projection);
    	glEnable(GL_DEPTH_TEST);
    	glEnable(GL_DEPTH_CLAMP);
    	glBindTexture(GL_TEXTURE_2D, textId);
    	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.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    965

    Re: Question of skybox drawing

    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.

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    381

    Re: Question of skybox drawing

    Are you using glDepthFunc(GL_LEQUAL) ?

  5. #5
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    212

    Re: Question of skybox drawing

    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.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    965

    Re: Question of skybox drawing

    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.

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    900

    Re: Question of skybox drawing

    It saved approximately 0.4ms. Not much [..]
    I would definitely consider such a change a nice improvement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •