ARB_depth_texture questions

Started by March 19, 2005 11:42 PM
6 comments, last by silvermace 15 years, 1 month ago
silvermace
Author
634
March 19, 2005 11:42 PM

hi all, i'm rendering my scene and then using glCopyTexSubImage to read back the framebuffer's depth info into a texture i created (with format DEPTH_COMPONENT) it dosn't seem to be working, its just all white... i've searched google with not much luck. its my understanding that the depth value should be clamped to 0-1, this is correct? any help would be greatly appreciated Cheers -Danu my code:


// init code
glGenTextures(1, &this->apiName );
glBindTexture( GL_TEXTURE_2D, this->apiName );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL );

// rendering code
device->flush();

// copy zbuffer into the depth texture
glBindTexture(GL_TEXTURE_2D, this->apiName);
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, this->width, this->height);

// also tried this, but no cigar:
// glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, this->width, this->height, 0);


"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
zedzeek
March 20, 2005 03:36 AM
thats cause the depth values are most likely in the range 0.998 -> 1.0 thus appear white
u can verfy this by constraining the znear - far values
eg change gluPerspective( 60,1, 0.1, 200 ) to gluPerspective( 60,1, 50, 200 );

another way is to render with linear fog, 0.0 == near 1.0 == far

silvermace
Author
634
March 20, 2005 03:44 AM
Quote:Original post by zedzeek
thats cause the depth values are most likely in the range 0.998 -> 1.0 thus appear white
u can verfy this by constraining the znear - far values
eg change gluPerspective( 60,1, 0.1, 200 ) to gluPerspective( 60,1, 50, 200 );

another way is to render with linear fog, 0.0 == near 1.0 == far
Legend!

I should have guessed, well.. we live and learn aye?

is this range of 0.998 -> 1.0 any use to me? i mean can it be used succesfully say in a depth of field shader?

if not, is there any way i could change this to be more usfull?
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Yann L
1,802
March 20, 2005 06:18 AM
Quote:Original post by silvermace
is this range of 0.998 -> 1.0 any use to me? i mean can it be used succesfully say in a depth of field shader?

if not, is there any way i could change this to be more usfull?

The entire range of the depth buffer (from 0 to 1) will be available in your depth texture, but due to the perspective nature of the depth buffer, distribution will not be linear. Although the 0.998 - 1.0 range is vastly exagerated. If you get that, then you have seriously screwed up the near plane. A more realistic range is something like 0.4/0.5 to 1. But keep in mind, that values down to zero will definitely appear on very near objects, so they should not be disregarded.

That said, the question is what you're planning to do with your depth texture. If it's any operation that will work on the actual depth values (for example shadow mapping, depth peeling, etc), then you can use it as is. If you want to use it for visualization purposes (ie. show the depth values as shades of grey), then you need to remap it to a more constrained range (0 to 255).
silvermace
Author
634
March 20, 2005 01:01 PM
it seems that the range zedzeek was suggesting must be right, because if it was 0.5-1 then wouldn't i see it as a grayscale image when i render it?

any info on how to re-map to a more linear scale so that i can visualise it through a grayscale image?

cheers
-danu
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
zedzeek
March 20, 2005 01:32 PM
i dont know about vastly exagetrated, perhaps slight though

say u have a near = 0.1 and far at 1000.0
a value at 0.1 unit distance will have a depth value of 0.0
a value at 1 unit distance will have a depth value of ~0.9
a value at 10 unit distance will have a depth value of ~0.99
a value at 100 unit distance will have a depth value of ~0.999
a value at 1000.0 unit distance will have a depth value of 1.0

thus the values from 100->1000 (90%) have gotta lie between ~0.999 and 1.0

Quote:any info on how to re-map to a more linear scale so that i can visualise it through a grayscale image?
like i said u can do with the standard pipeline, linear fog start == near, end == far.
or something similar is a fragment program
Yann L
1,802
March 20, 2005 01:46 PM
Quote:Original post by zedzeek
i dont know about vastly exagetrated, perhaps slight though

say u have a near = 0.1 and far at 1000.0

That's what I meant by having the near plane completely messed up :) 0.1 as near plane is insane, you'll waste almost your entire depth buffer precision in a range that will almost never be used.

A near plane value of 1.0 is much more realistic. Even larger, if you can afford it in terms of visual artifacts.

Silvermace: what is your current near and far plane range ?
silvermace
Author
634
March 20, 2005 03:13 PM
im currently using near:0.1, far:200, but i'm going to change that, it was really just for testing purposes (my engine is in its early stages)

thanks for all the help guys
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Share:

This topic is closed to new replies.