Results 1 to 2 of 2

Thread: Is there any way to calculate depth without using z-buffer?

  1. #1
    Newbie Newbie
    Join Date
    Jan 2019
    Posts
    1

    Is there any way to calculate depth without using z-buffer?

    Hello.
    I'm very beginner, so kind explanation and tolerance will be really appreciated.
    I coded simple game with C++ and openGL.
    And then, I want to calculate the depth of objects.
    (to color them differently according to their depth)

    I found the concept of z-buffer, and thought.
    "Oh. Depth is already calculated! Just use it."
    But problem occurs.
    Almost every objects has z-buffer in 0.9 ~ 1.0.
    I noticed that the reason is non-linear distribution of z-buffer.
    (May the designer of z-buffer wanted to calculate closer object more accurately, right?)

    So, I linearized them with code.
    (https://www.opengl.org/discussion_bo...ixel-s-Z-coord)

    After linearizing them, distribution be linear.
    But other problem occurs.

    000204.jpg

    Can you see?
    Strange discontinuity ruined my graphic.
    I suppose the reason is limited memory of z-buffer, but not sure.

    So I decided just ignore z-buffer, and calculate it own way.
    But is there any nice way to do it?
    Or the problem above can be solved while still using z-buffer?

    Please help me.
    Thank you.

    edit---------------------------------

    And I feel really sorry about do not post the part of my code here.
    I do not have permission yet from my partners about it...
    If I got it, then I would immediately post it.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    Quote Originally Posted by evergreen View Post
    Almost every objects has z-buffer in 0.9 ~ 1.0.
    I noticed that the reason is non-linear distribution of z-buffer.
    (May the designer of z-buffer wanted to calculate closer object more accurately, right?)
    A perspective projection divides all 3 coordinates by eye-space Z, so the transformation from eye-space Z to window-space Z (i.e. depth) will always look like a/z+b for some constants a, b. A perspective projection preserves planarity, so depth can be calculated without requiring a division operation for each pixel.

    Quote Originally Posted by evergreen View Post
    I suppose the reason is limited memory of z-buffer, but not sure.
    I assume that you're referring to the limited precision?

    If most of your depth values are close to 1.0, this may indicate that the near distance used in the perspective transformation is too small. For any factor N>1, approximately 1/N of the depth values correspond to eye-space -Z values greater than N times the near distance.

    Quote Originally Posted by evergreen View Post
    So I decided just ignore z-buffer, and calculate it own way.
    But is there any nice way to do it?
    Or the problem above can be solved while still using z-buffer?
    If you're using shaders, you can just use the eye-space Z coordinate.

Similar Threads

  1. ray casting and calculate depth value
    By feizMilan in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 05-08-2015, 11:15 PM
  2. Framebuffer depth test with depth and stencil buffer
    By moldyviolinist in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 07-29-2013, 08:21 PM
  3. Depth buffer reading and depth buffer test
    By BurningLegion in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-15-2007, 04:09 AM
  4. depth buffer -> depth texture -> depth buffer
    By Codemonkey in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 12-23-2005, 06:27 AM
  5. why depth buffer save to image file can not display depth information
    By victorswan in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-27-2001, 09:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean