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.

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 on other sites
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 on other sites
OK, thank you very much :)

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 9
• 11
• 9
• 9
• Forum Statistics

• Total Topics
633715
• Total Posts
3013495
×