PDA

View Full Version : culling polygons (when too near)



01-09-2002, 10:15 AM
Hi,
I'm still working on my 3D-shooter, and my actual Problem is, that when I'm too close to an Oject (some Polygons), I can look through it, although it's actually in front of me.
I've got that problem since I changed the "near"-parameter of the gluPerspective(...) function from 0.01f to 1.0f (because I've read that this parameter should be >= 1.0f).

What can I do?

peter

Bob
01-09-2002, 10:20 AM
What you can do is to move it back again (it does not have to be greater than 1.0). Just make sure you don't set it to zero or less.

01-09-2002, 11:43 AM
Hello,
I've just read that the z-Buffer doesn't work fine if the near-value of the gluPerspective-function gets to close to zero. It's right that it's not allowed to set it zero or less, but it is recommended to set it at least at 1.0f.
I've tried settin the near-value to 0.001f, and the result was very bad. At 0.01f it's not so very bad, but worse than at 1.0f.

Isn't there another solution to avoid the clipping-effect?

peter2345

ZubZorro
01-09-2002, 02:03 PM
Prevent the player from moving so close to the object?

It should be an easy addition to what you already have.

DFrey
01-09-2002, 02:27 PM
Setting zNear less than 1 is ok, as long as you also change zFar so that the zNear to zFar ratio remains reasonable. I usually try to keep the ratio around 1000 for 16 bit depth, and 10000 for 24 bit depth, though that may be a bit conservative.

Bob
01-10-2002, 03:42 AM
I've just read that the z-Buffer doesn't work fine if the near-value of the gluPerspective-function gets to close to zero.

Both right and wrong. If the zNear get clsoe to zero, you MIGHT have some strange behaviour in the Z-buffer, but that depends in the zFar value. As DFrey says, the absolute value does not matter, but zNear relative the zFar does. The Z-buffer will only behave strange if the near Z-plane is close to zero AND the far plane is far away (thats relative, as DFrey said, a ratio of about 1-10k is good). Having a zNear or 0.0001 and a zFar of 0.1 is not bad at all.

peter2002
01-10-2002, 05:05 AM
Ok, thanks for your answers
and for correcting me.
So, did I understand it right, that changing the depth-buffer size (in the PIXELFORMATDESCRIPTOR-setting) from 16 to 24 or more, I'll get better results with depth-testing?
One the one hand I'd pretty like changing the zNear back to 0.01f, but on the other hand, I need a quite big value for zFar (at least 100.0f), because the scene should be quite big. So what value shall I take for the depth-buffer size?

thanx,
peter

Bob
01-10-2002, 09:22 AM
Increasing the size of the depthuffer helps.

Like DFrey said, you should keep a near:far ratio of about 1000 to 10000, depending on the size of the depthbuffer. So if you have your far plane at 100, then you can safely set the near plane somewhere between 0.1 and 0.01 without worrying too much about precision problems.