Jump to content
  • Advertisement
Sign in to follow this  
EonStrife

OpenGL Simple question about NDC and Z-buffer

This topic is 4887 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 guys, I'm wondering about NDC and Z-Buffer. After we get the clip coordinate, we divide each component(x, y, z) with w to get the NDC with -1 <= x, y, z <= 1. The question is, for z component of NDC, do we use all -1 until +1, or just 0 until 1 ? And how does OpenGL convert the z NDC to store in depth buffer ? And how does depth buffer store the data ?(-1 until +1 ? or floating ? or integer ?). Thanks :)

Share this post


Link to post
Share on other sites
Advertisement
Quote:

The question is, for z component of NDC, do we use all -1 until +1, or just 0 until 1 ?

The entire -1 to 1 range, just as for normal x and y coordinates.

Quote:

And how does OpenGL convert the z NDC to store in depth buffer ?

Quickly resumed from the specs: the normalized device coordinate zd is converted to a window coordinate zw by the following equation:

zw = ((f-n)/2)*zd + (n+f)/2

n and f are set by the glDepthRange() command. By default, n is 0, and f is 1. So, by default the above equation remaps the -1 to 1 NDC range into a 0 to 1 range.

Quote:

And how does depth buffer store the data ?(-1 until +1 ? or floating ? or integer ?).

It stores the window coordinate zw computed above. The internal storag format is implementation dependent, and irrelevant for API usage.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!