• Advertisement
Sign in to follow this  

The furthest point on the screen

This topic is 2630 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

Is there any robust solution to get the furthest point on the camera viewport before rendering and then set the final camera far plane which is determined by the furthest point?

Share this post


Link to post
Share on other sites
Advertisement
Any reason to do this?

You could take every object, and find the distance from every vertex to the near plane. But the time you spend doing this may make whatever your trying to do (my guess is performance improvement) not worth it.

Share this post


Link to post
Share on other sites
It usually makes more sense to think about the near plane than the far plane, since this affects the z-buffer precision a lot more (which I guess is what you want?).
Plus, what Argo15 said.

The "normal" thing to do is decide how far you want to see before you start, and fade out distant object into "fog" some distance before that. Using a colour similar to the sky colour usually works good.

But, if you still want to do this and take all eventualities (alpha tested geometry, fragment kill, fragment shader writing depth, etc.) into account, you have little choice but to render a z-only pass first and then reduce that render buffer to a single value, in much the same manner as you would build mipmaps, a histogram, or calculate an average luminescence value. Except of course, you would use a max function. The max function rules out some well-known optimizations, such as taking advantage of anisotropic filtering or sampling in between texels, so it probably won't be lightning fast.

PS: see this.

[Edited by - samoth on December 7, 2010 9:23:44 AM]

Share this post


Link to post
Share on other sites
I would just set the far plane to infinity. For a typical perspective projection this amounts to factoring out the term (Far / (Far-Near)) from the projection matrix (it appears in two places) and replacing with 1. It has negligible impact on z precision.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement