# When and how does openGL calculate F\_depth(depth value)

**URL:** <https://community.khronos.org/t/when-and-how-does-opengl-calculate-f-depth-depth-value/106086>\
**Category:** OpenGL: Basic Coding\
**Created:** [July 25, 2020, 4:37am UTC](https://community.khronos.org/t/when-and-how-does-opengl-calculate-f-depth-depth-value/106086 "2020-07-25T04:37:41Z")\
**Posts on this page:** 1\
**Showing post:** 26

<div class="post-metadata">

**Author:** ![nirla123](https://community.khronos.org/user_avatar/community.khronos.org/nirla123/32/6081_2.png) [@nirla123](https://community.khronos.org/u/nirla123)\
**Post date:** [July 26, 2020, 8:59am UTC](https://community.khronos.org/t/when-and-how-does-opengl-calculate-f-depth-depth-value/106086/26 "2020-07-26T08:59:08Z")

</div>

> [@GClements](#):
>
> That is the formula used for transforming NDC to window coordinates (x,y) and depth (z). Note that `farVal` and `nearVal` are the `glDepthRange` parameters, _not_ the near/far distances used to generate the projection matrix.
> 
> Note that the calculation for zNDC-\>zw is equivalent to this one:
> 
> > [@GClements](#):
> >
> > depth = n + (f-n)\*(zNDC+1)/2
> 
> just factored differently.

I just got everything how the F\_depth and how [-1,1] to [0,1] mapping occurs. I very much thank you and Alfonse for that.

But, one thing, during window transformation z value seems to map to [0,1], meaning (x’,y’,z’), where x’,y’,z’ are the window transformed coordinates. meaning (x’,y’,z’) don’t span a plane, they span a space, so while drawing, the z’ coords are ignored?

---

_[View the full topic](https://community.khronos.org/t/when-and-how-does-opengl-calculate-f-depth-depth-value/106086)._
