Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: (gl_FragCoord.z / gl_FragCoord.w) for quick depth calculation, camera to fragment?

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2009
    Posts
    20

    (SOLVED) Is (gl_FragCoord.z / gl_FragCoord.w) a valid depth formula?

    Looking at this tutorial, I noticed an interesting little calculation to get per-fragment depth from the camera.

    float z = gl_FragCoord.z / gl_FragCoord.w;I find this works for me, and that it appears to be fairly accurate in terms of distance.

    Now, certain other people are very very certain that this is not a valid way to get depth /distance from the camera.

    Can anyone shed any light onto the following:

    (a) Whether this is in fact a valid and accurate way to get depth;
    (b) How the mathematics behind it work.
    Last edited by Nick Wiggill; 12-05-2012 at 08:20 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •