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 7 of 7

Thread: What would I see if I bind the depth buffer texture on to a quad?

  1. #1
    Intern Contributor
    Join Date
    Sep 2016
    Posts
    71

    What would I see if I bind the depth buffer texture on to a quad?

    I'm currently binding the Color Texture of my Color Frame Buffer on to a Quad. I see my scene inverted so I know it's working. But when I render the depth buffer texture on this quad, it's all red and I'm not sure if it's that normal or not.

    What are ways I can test if the depth buffer texture is right? With the color buffer I see the scene inverted if I bind the texture onto a quad, but I don't know what to expect with the depth buffer texture. Thanks!

    By the way, I'm using WebGL 1.
    Last edited by hashbrown; 06-05-2017 at 10:23 PM.

  2. #2
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    420
    This is most probably (and can be) normal. The depth buffer is very precise near the near value of the projection matrix, and quickly looses its precision, producing values near 1.0.
    Try to look at objects close to the near value of your projection matrix.
    You can also relinearize or fake a linearization if that could be enough for your needs.

    Edit: you can also try to reduce the far value of the perspective the most you can (see it to the farthest visible object for example). This might not help to vizualize everything. But will definitely help in having a more precise depth buffer.
    Last edited by Silence; 06-06-2017 at 12:30 AM.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,124
    Quote Originally Posted by Silence View Post
    You can also relinearize ...
    This can be very useful for debugging, particularly when rendering shadow maps (which are depth buffers) for the first time.

    However, the formula in this link you posted doesn't look right. A formula which takes a 0..1 depth generated by a perspective projection and gives you back the eye-space Z value should result in: f(0) = -n, f(1) = -f. This doesn't.

    I think you'll find what you want here is:

    Code glsl:
       eye.z = near * far / ((depth * (far - near)) - far);

  4. #4
    Intern Contributor
    Join Date
    Sep 2016
    Posts
    71
    Thanks Silence and Photon! I'll give it a try. I'm trying to use the depth buffer for my water shader. We'll see how that comes along. Thanks again

  5. #5
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    420
    Quote Originally Posted by Dark Photon View Post
    This can be very useful for debugging, particularly when rendering shadow maps (which are depth buffers) for the first time.

    However, the formula in this link you posted doesn't look right. A formula which takes a 0..1 depth generated by a perspective projection and gives you back the eye-space Z value should result in: f(0) = -n, f(1) = -f. This doesn't.

    I think you'll find what you want here is:

    Code glsl:
       eye.z = near * far / ((depth * (far - near)) - far);
    Thanks for the fix !
    You can be at the top results of a google research and still be wrong... (https://www.google.fr/?gws_rd=ssl#q=...e+depth+buffer)

  6. #6
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,124
    Quote Originally Posted by Silence View Post
    Thanks for the fix !
    You can be at the top results of a google research and still be wrong... (https://www.google.fr/?gws_rd=ssl#q=...e+depth+buffer)
    The top search result that comes up there:


    appears to be correct. However this:


    is not.

    Note that the stackoverflow link uses zNear = -near and zFar = -far, as the follow-up comment mentions.

  7. #7
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    417
    Quote Originally Posted by hashbrown View Post
    What are ways I can test if the depth buffer texture is right?
    another way would to visualize it, make a "depth shader" and draw a screen-wide textured rectangle:
    Code :
    float depth = texture(depthtexture, texcoords).r;
    vec4 color = vec4(depth, depth, depth, 1);

Posting Permissions

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