Hi.
First of all, I dont use the ogl view, projection matrix stuff. Instead, I load the stuff myself.
I use column vectors and a left handed coord sys. Just like D3D. I mean, the vertex's coord are defined in positive z space.
When I transform the camera, everything seems to be ok. The camera goes just where I want it to be...
It seems, that everything is just rendered fine. Some days ago, I implemented SSAO and realized, that the depth buffer is very bright. I mean, the depth buffer values are very high at 1.0.
If I pow the depth values in the pixel shader by 30 or so, i.e. pow( depth, 30 ),
the depth values looks just fine! the depth buffer just looks like a depth buffer and not as before, a white plane. So, depth values are just there.
Then I observed the projection matrix. It is the one from the book Realtime Rendering. This matrix can be found nearly on every other website, including the microsoft's d3d site.
It's the following:
vec4_t vcX(2.0f*n/width,0.0f, 0.0f, 0.0f) ;
vec4_t vcY(0.0f, 2.0f*n/height, 0.0f, 0.0f) ;
vec4_t vcZ(0.0f, 0.0f, f/(f - n), -2.0f*n*f/(f-n) ) ;
vec4_t vcW(0.0f, 0.0f, 1.0f, 0.0f ) ;
I hope the formatting is ok!
Now, lets just quickly observe the values for the projected z coordinate, which goes into the depth buffer.
It is
x_p = ...
y_p = ...
z_p = (z*f/(f-n)-2.0*n*f/(f-n))/w_p
w_p = z
, if you mult the view space vector with the projection matrix.
z: view space z value
f: far plane dist
n: near plane dist
Now, lets assume f=1000, n=0.1, z=1.0
Now, lets calc:
z_p = (1.0*1000.0/(1000.0)-2.0*0.1*1000.0/(1000.0-0.1))/1.0
/// I put 1000-0.1 = 1000.0
z_p = 1.0 - 2.0*0.1 = 0.8
I hope this is clear enough. But as you can see, the view space z=1.0 value maps
to the depth value of z_p=0.8.
If you use z=2.0, then z_p=0.9!!!!
So what happening here? My depth buffer's values are defined within the space [0.8,1.0]
What did I do wrong, or whats wrong with the projection matrix?
Thanks
Alex