Sign in to follow this  
masterbubu

SkyBox - need help

Recommended Posts

Hi, How can i make the sky box be infinite far away? I have tried to tide up the box to the camera , so when the camera moves, the box moves with it. but its not perfect because on some point, the box will start clipping the scene objects. can anyone have better idea?

Share this post


Link to post
Share on other sites
You are on the right track.
+ Render the skybox first, but disable depth test, so the box won't write the depth buffer, so won't clip anything.
Or you can set depth range to 0.99999 to 1.0 when drawing the skybox, and set depth test to GL_ALWAYS. That way you never have to clear the depth buffer at all, because the skybox will do it for you.

Share this post


Link to post
Share on other sites
If you're using shaders, there's an easy trick that makes geometry become infinitely far away.
After transforming your vertex position in the vertex shader, set the z component to equal the w component.
position = ...;
position = position.xyww;//i.e. position.z = position.w

At the pixel level, depth is computed by dividing z and w -- so if z and w are the same thing, depth comes out as 1.0 (100% depth), which means it's always at your camera's far plane.
Quote:
Original post by szecs
That way you never have to clear the depth buffer at all, because the skybox will do it for you.
This used to be good advice, but on modern GPUs that use ZBuffer compression, you're advised to clear the depth every frame. These days clearing the ZBuffer is extremely fast, and if you don't clear it then the compression scheme eventually starts hurting performance instead of increasing performance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this