How to set zFar?

Started by
5 comments, last by 3dmaniac 16 years, 7 months ago
Is it possible to change zFar after calling gluPerspective/glFrustum, or can I make certain objects (in this case my skybox) ignore the far clipping plane? EDIT: Hmm, could calling glDisable(GL_DEPTH_TEST), drawing the skybox and then calling glEnable(GL_DEPTH_TEST) work? Or something like that?
Advertisement
For the Skybox I suggest rendering a Box centered at the camera at the size of 1.0f or 2.0f (so very small) with disabled z writing. This in the end looks like it has the size of infinity, but there are no problems with blocky textures, etc.

Edit: Yes, that would be the way I use it everytime
glDisable(GL_DEPTH_TEST); //disable reading of z-depth

or

glDepthMask(false); //disable writing of z-depth.

Cheers! =)
"Game Maker For Life, probably never professional thou." =)
Alright, thank you.
The downside is of course that you first fill the whole screen with the skybox and then overwrite most of it with other stuff. Nothing is keeping you from doing the box last. Million ways to do it. One is obviously to center it around the camera and give it the right size (ie. far plane - very small number).
f@dzhttp://festini.device-zero.de
normally u wanna draw the skybox last (but before the blended stuff);
to make sure the skybox is drawn behind all other gemetry call

depthtest is enabled but depthwrites are not
glDepthRange(1,1);
draw skybox
glDepthRange(0,1);
From Depth_In-Depth ati guide:

"One of the issues in changing existing code rendering the skybox first to rendering it last is that the box
will usually get clipped in the corners by the far clipping plane and/or by previously-rendered geometry.
This may happen because the skybox is modeled by an artist and has a fixed size, but even a
programmer generated skybox may see issues like this. Instead of pushing the far clipping plane back a
solution to these issues is to leave the far clipping plane untouched and instead simply peg the depth of
the skybox to the far clipping plane. There are different methods to achieve this. The perspective divide
produces a depth value of z / w, and the far clipping plane is always at depth 1.0, so one method to peg
an object to the far plane would be to arrange for z to be equal to w. This can be done in a vertex shader
by simply assigning w to z after transformation as the following code fragment shows:

// Out.position = mul(mvp, vertex);
Out.position = mul(mvp, vertex).xyww;

The only change necessary is to add the .xyww swizzle in the end. As a bonus, this compiles down to
just three instructions instead of four."

This topic is closed to new replies.

Advertisement