Sign in to follow this  

gluPerspective - Near & Far problems

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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.

Your large objects have a large radius like 1000 and more?
There is a special matrix for this case.

Share this post


Link to post
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 this post


Link to post
Share on other sites
[quote name='polar01' timestamp='1293157726' post='591264']
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...
[/quote]
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 this post


Link to post
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 this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1311762516' post='4841041']
Very small near-plane numbers (like 0.1) cause lots of precision problems.
[/quote]
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 this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1311767026' post='4841056']A near plane at 0.1 is, in itself, nothing wrong at all.[/quote]Edited my previous post to make it less misleading.[hr]Check out the graphs [url="http://www.codermind.com/articles/Depth-buffer-tutorial.html"]on this page[/url] - 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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this