Jump to content
  • Advertisement
Sign in to follow this  
Nasam

OpenGL Displaying depth buffer as an image

This topic is 3537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What I wanted is displaying depth information of the scene as an (bmp or tga ) image. (Using OPengl api's) For this after reading depth value for a pixel from the depth buffer, same value is taken as R, G ,B for that pixel and written to the image file. This is giving correct result(grayscale image). For an object( say 3D teapot or 3D text) it is obvious that different pixels are at different depths if that object is slightly tilted. But it is not showing depth variation in this case( not showing different gray scale levels). Why this happens? And how to correct this error? Thanks in advance [Edited by - Nasam on December 5, 2008 3:12:41 AM]

Share this post


Link to post
Share on other sites
Advertisement
A depth buffer often has a resolution of 16/24 bits, but a standard image only has 8 bits for each color channel. Additionally the constribution of the z values is not linear. With this in mind you will only see a single gray-value for objects which are far away. For objects which are closer to the near-plane you will see more variation in gray-values.

If you want to virtualize the z-buffer try to map the z-value in cameraspace to 0..1 and render this to a color buffer (easily done in shader).

--
Ashaman

Share this post


Link to post
Share on other sites
Quote:
Original post by Ashaman73
A depth buffer often has a resolution of 16/24 bits, but a standard image only has 8 bits for each color channel. Additionally the constribution of the z values is not linear. With this in mind you will only see a single gray-value for objects which are far away. For objects which are closer to the near-plane you will see more variation in gray-values.

If you want to virtualize the z-buffer try to map the z-value in cameraspace to 0..1 and render this to a color buffer (easily done in shader).

--
Ashaman




thank you very much for the reply.

But it is not showing variation for object which is nearer(forground 3d object entirely in darker shade and objects far away with ligher shades).

Share this post


Link to post
Share on other sites
Quote:
Original post by Ashaman73
A depth buffer often has a resolution of 16/24 bits, but a standard image only has 8 bits for each color channel. Additionally the constribution of the z values is not linear. With this in mind you will only see a single gray-value for objects which are far away. For objects which are closer to the near-plane you will see more variation in gray-values.

If you want to virtualize the z-buffer try to map the z-value in cameraspace to 0..1 and render this to a color buffer (easily done in shader).

--
Ashaman




thank you very much for the reply.

But it is not showing variation for object which is nearer(forground 3d object entirely in darker shade and objects far away with ligher shades).

Share this post


Link to post
Share on other sites
Perhaps you can try using GLIntercept to make sure the depth buffer you're saving is accurate.

One of the features GLIntercept offers is:
-Saving of the OpenGL frame buffer (color/depth/stencil) pre and post render calls. The ability to save the "diff" of pre and post images is also available.

Also, as per Ashaman73's suggestion, maybe you should make your objects [much] bigger. If they're relatively small, the slight variations in depth might not translate to different grayscale shades. But if the object is bigger, there should be bigger differences in depth and therefore you should see slightly more different shades of gray.

That would explain why your objects at different distances appear as different shades, but within the same object, there is little (to no) variation in colour.

Share this post


Link to post
Share on other sites
thanks for the information. I am trying to use GLintercept,(installed it already). How can i proceed to use it. Please help me in this regard.

Share this post


Link to post
Share on other sites
This might be solved but if you want to make your own shader heres the code I use

float z = ( gl_FragCoord.z / gl_FragCoord.w ) * farReciprocal;

Where farReciprocal is the reciprocal of the far plain ( IE, for a far plan of 1000 it would be 1.0 / 1000.0 or 0.001 ) then you can just do gl_FragData[0] = vec4( z, z, z, 1.0 ); to get the grey scale

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!