PDA

View Full Version : Disabling the near clipping plane?



xvs
09-01-2000, 01:42 PM
Is there any way I can disable the near clipping plane? Or at least, make it approach 0 without distorting my world?
I'm currently using the following:



glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, near, 200.0);

^^^^
near = 1.0 in here. Although it works fine, gl is clipping my polygons 1.0 meters away from the camera, which is bad. Appart from scaling everything up (by a factor of 100, which is bad for the z-buffer), what would be another solution to my problem?

Thanks

xvs
09-01-2000, 04:13 PM
I've found a temporary workaround, which is to use glScalef(10, 10, 10) after glLoadIdentity(). Any real fix though?

wolfman8k
09-01-2000, 11:22 PM
Just set it to 0.0001f

Bob
09-02-2000, 01:56 AM
Be aware, setting the near plane TOO close, will kill the z-buffer. So this is not recomended. Same effect with placing the far plane too far away.

xvs
09-02-2000, 08:10 AM
The problem is that setting the near clipping plane to anything but 1.0f distorts what I render, making a very cool warping effect of some sort :) but it doesn't fix the problem. Unless the problem is with glFrustum; is there a way to manually set those, without messaing with all those amtrix calcs?

john
09-02-2000, 03:41 PM
You *can't* disable the near clip plane. It's there because it's a fundamental aspect of cameras... not just opengl cameras, but ALL cameras. The near clip plane is effectively the retinal plane... the thing that captures the light from the lens. The *far* plane is a device introduced by graphcis cameras to get around precision problems, and so you could (theoreticaly) disable THAT. real cameras don't have a far plane, but they certainly have a retinal plane.

cheers
John

09-02-2000, 09:39 PM
The image distorts if you set the near plane too close because as Z nears 0, X approaches infinity. If you were to remove the near plane no polygons would be cliped and the would would be completely distorted to the point where it would be unviewable.

There was a thread several weeks ago which discussed this topic. If I remember correctly the distortion occurs because of a combination of the near AND far clipping planes. It's a matter of playing around with both Planes until you get the right ratio. You could use gluPerspective to make it easier or set your collision detection to prevent you from getting too close to an object.

I use the following code with my latest programme and I don't get any problems.

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

Bob
09-03-2000, 01:58 AM
While we are into the discussion about near/far plane, and z-buffer distortion, I can add this. When setting the near and far plane, you get a near to far ratio (ratio=far/near), and you will loose log2(ratio) bits of depthbuffer precision (log2(ratio) is the two-logarithm or ratio). So, if you let the near plane approach zero, ratio will approach infinity, and you will loose 'infinity' number of bits in you depthbuffer, but you generally only have 16 or 32 of 'em http://www.opengl.org/discussion_boards/ubb/smile.gif
Same effect when far approaches infinity.

So this tells us one thing, keep the near to far ratio as small as possible, or you will loose depthprecision (VERY important if you are using 16-bit depthbuffer)

gluPerspective is good when you want to setup a standar camera for games and similar application. But when you want the frustum to cover a certain part of the world, and no more, you are more or less forced to use glFrustum (don't get me wrong, I use gluPerspective most of the time, and I like it too, but it has it's drawbacks sometimes http://www.opengl.org/discussion_boards/ubb/tongue.gif )

john
09-03-2000, 03:39 PM
You *can't* not have the near plane. You can theoretically set it to the plane at infinity, but it *IS* used to define projection.
Why? Because projection is a matrix to take a dimensional space to a lesser dimensional space. In this case you're talking about projecting 3D onto a 2D plane (as opposed to some 4D space onto a 3D space, or a 5D space onto a 1D space or whatever you want to make up). The near plane *IS* the resulting plane of projecting 3D onto 2D. It MUST, by defn of projection, therefore exist.

Setting the retinal/near plane to inf gives ortho proj. Anything else gives perspective.

cheers
John