gluPerspective - Near & Far problems

Started by
5 comments, last by Hodgman 12 years, 8 months ago
Hi,

I currently use the following code to set up my perspective.

gluPerspective(45, aspectRatio, 0.1f, 1000.f);

The problem is that with large objects, or very small one... I see nothing.

If I update the near/far planes... I got precisions problems with the gluUnproject etc...

So, can you tell me how you handle this ?

Thx
--------------------------------------------------------------------------------Aurora Studio - PureLight - Animation & rendering software and API.http://www.polarlights.net
Advertisement
I imagine you are doing what seems to be common: using the depth buffer to select object. Use another solution like an math library to do a ray cast intersection test.

Your large objects have a large radius like 1000 and more?
There is a special matrix for this case.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Does someone has an idea to solve the problem. Far and near plane are important, so they depend of the scene (size of the scene).

- I can use the scene bounding box to change/compute the far/near plane ?
- Have you experimented this ? There is no side effect ?

Thanks
--------------------------------------------------------------------------------Aurora Studio - PureLight - Animation & rendering software and API.http://www.polarlights.net

The problem is that with large objects, or very small one... I see nothing.
If I update the near/far planes... I got precisions problems with the gluUnproject etc...

Actually you don't see polygons in front of near and behind far clipping planes. It is normal, since clipping planes define view frustum.

There are many techniques to handle large scenes. I suggest you to split your scene into several parts by distance/size each with its own near/far clip planes. Try to keep far/near ration less or equal to 10e5.

It's very important to set your near plane out as far as possible. The value used for the far plane is much less important.

Very small relative near-plane numbers (like 0.1m compared to objects that are 100m away) cause lots of precision problems.

If things start disappearing because your near-plane value is too large, you can always compensate by moving the 'camera' position backwards.

What units are you currently working in (metres, centimetres), and what size scenes are you trying to render?

Very small near-plane numbers (like 0.1) cause lots of precision problems.

A near plane at 0.1 is, in itself, nothing wrong at all. It's all about the relative scale of your scene. The advice itself, that a very small near-plane distance is bad, is very much correct, but when the actual value is entirely dependent on the scale of the scene, then giving an example of a small value can be a very dangerous, and perhaps outright wrong, piece of information.

What matters are the ratios of the distances between the near plane and the objects of interest, not the value of the near clip plane alone.
A near plane at 0.1 is, in itself, nothing wrong at all.
Edited my previous post to make it less misleading.[hr]Check out the graphs on this page - they show how when using smaller 'near' values, how the precision-distribution curve becomes much steeper at the near end.
As a general rule of thumb, the near plane value should be as large as possible, while the value of the far-plane is much less important.

e.g. in your situation, by changing the near value from '0.1' to '1', your z precision in the range between 1unit and 1000units will be approx 10x better.

This topic is closed to new replies.

Advertisement