# gluPerspective - Near & Far problems

This topic is 2639 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.

There is a special matrix for this case.

##### Share on other sites
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

##### Share on other sites

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.

##### Share on other sites
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?

##### Share on other sites

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.

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 10
• 16
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632929
• Total Posts
3009276
• ### Who's Online (See full list)

There are no registered users currently online

×