Sign in to follow this  
kavaari

The furthest point on the screen

Recommended Posts

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
Also note please read this http://www.gamasutra.com/blogs/BranoKemen/20090812/2725/Logarithmic_Depth_Buffer.php, it is not directly related to the question, though it will make your precision linear everywhere :) ... you'll find that this can be better for distant areas.

Share this post


Link to post
Share on other sites

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