PDA

View Full Version : Skybox



Phoenix
08-05-2002, 11:38 AM
Hi!

I have coded a function that renders a Skybox, but I dont know if I did it in the proper way.
First of all: how do you build the coordinates of the box in order to draw it in fullscreen and behind all the objects at the maximum distance possible???
And then, how do you let it be always "centered"? if the observer moves the box should be always at the same distance!
Thanx!

AdrianD
08-05-2002, 12:46 PM
- if you skybox looks correct -> it is correct (how it look is the only thing that counts)
- easiest way to get a correct skybox: just set the skyboxposition to the global cameraposition(global = world space)
and change only the orientation of the skybox.

Phoenix
08-05-2002, 02:28 PM
uhmm...I haven't explained very well my problem.
for example: if I have a camera-settings like this <ANGLE=90, NEAR_PLANE=1, FAR_PLANE=10000>, what coordinates should have to be assigned to the Skybox cube in order to make the front face appear in the full-screen??? I thought that the right way was to build a cube with the size of the far_plane but this is incorrect. My problem is just this.
Thanx http://www.opengl.org/discussion_boards/ubb/wink.gif

BadMmonkey
08-05-2002, 04:18 PM
I have always just drawn the skybox first (ie before other geometry) by applying only the camera orientation transform (so no translation), and disabling depth test and depth writes so that the size of the box doesn't matter, and it will never occlude other geometry (which is what you want, as the sky should generally be the furthest "thing" away).

The downside to doing it this way is the cost of fillrate... you are drawing to a lot of pixels that will probably be covered up.

DFrey
08-05-2002, 09:57 PM
You could set the depth range to (1,1) and draw the skybox last. Also use the right depth test function of course.

WhatEver
08-06-2002, 04:44 PM
-Set Modelview matrix
-Load identity
-Push matrix
-Rotate by the inverse of your view direction
-Disable depthtest
-Draw Skybox
-Pop matrix
-Enable depthtest

Now do all your camera and model transformations. This ensures that your skybox is plotted into the framebuffer before anything else is drawn.

WhatEver
08-06-2002, 04:46 PM
BTW, the skybox dimensions can be 1x1x1 with the method I mentioned above so you don't have to worry about the box getting clipped.

Jambolo
08-06-2002, 09:13 PM
WhatEver: Not quite right...

Here are two ways depending on your code to orient the camera:




Clear
LoadIdentity
LookAt( ex, ey, ez, cx, cy, cz, ux, uy, uz )
PushMatrix
Translate( ex, ey, ez ) // Move skybox with the camera
Disable( DEPTH_TEST )
DepthMask( FALSE )
draw_sky_box();
Enable( DEPTH_TEST )
DepthMask( TRUE )
PopMatrix
... draw the world






Clear
LoadIdentity
Rotate( -a, vx, vy, vz ) // rotate camera
Disable( DEPTH_TEST )
DepthMask( FALSE )
draw_sky_box();
Enable( DEPTH_TEST )
DepthMask( TRUE )
Translate( -ex, -ey, -ez ) // translate camera
... draw the world


You need to disable zbuffer writes so the sky box does not occlude anything.

There is a problem with drawing the skybox last -- the center of a face of the skybox is much closer (58%) than the corners. Is there a way ensure that every fragment in the skybox is drawn at the far clipping plane?

[This message has been edited by Jambolo (edited 08-06-2002).]

DFrey
08-06-2002, 10:15 PM
Is there a way ensure that every fragment in the skybox is drawn at the far clipping plane?

Yes. Simply set the depth range to [1,1]. Which is what I mentioned above.

WhatEver
08-07-2002, 01:21 PM
Jambolo, your second method is what I posted http://www.opengl.org/discussion_boards/ubb/smile.gif.