Jump to content

  • Log In with Google      Sign In   
  • Create Account


Converting depth to linear view-space depth ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 lipsryme   Members   -  Reputation: 1002

Like
0Likes
Like

Posted 31 August 2012 - 02:09 PM

Is it possible to do that ?
What I've done before in DX9 is render "viewPos.z / farClip to a seperate render target for usage in e.g. ssao.
Now what I'm thinking is that having the opportunity to sample HW depth inside the shader using DX11, couldn't I instead sample my hardware Z buffer and somehow convert it to the linear space format I need for ssao ?
Or is this just not possible and I have to have this seperate depth texture ? It just seems redundant to me...

Edited by lipsryme, 31 August 2012 - 02:10 PM.


Sponsor:

#2 MJP   Moderators   -  Reputation: 10632

Like
0Likes
Like

Posted 31 August 2012 - 03:01 PM

It's possible if you have the original projection matrix used when rendering the depth:
float LinearDepth(in float zw)
{
    return Projection._43 / (zw - Projection._33);
}


#3 lipsryme   Members   -  Reputation: 1002

Like
0Likes
Like

Posted 01 September 2012 - 04:59 AM

Hmm all I seem to be getting is pure white with the objects being black/dark greyish when I'm extremely close to them.
sample it like this:
output = DepthBuffer.Sample(PointSampler, input.UV);
output = ToLinearZ(output.r);

I simply use the same projection matrix I'm using for the whole scene (I just have one).
As the projection matrix does not change it would be the exact same one as when I rendered my geometry or not ?

Edited by lipsryme, 01 September 2012 - 05:04 AM.


#4 MJP   Moderators   -  Reputation: 10632

Like
0Likes
Like

Posted 01 September 2012 - 11:52 AM

The value you get will be the exact view-space Z value of the pixel, so it will be of the range [0, FarClip]. If you want to visualize it, you should divide it by FarClip to bring it back to [0, 1].

#5 lipsryme   Members   -  Reputation: 1002

Like
0Likes
Like

Posted 01 September 2012 - 01:42 PM

Hmm it doesn't seem to work in combination with my ssao.
What I had before was a R32 texture rendering the depth like this:
viewPos.z / farClipDist
And inside the ssao I sample from this texture two times using different tex coords.

Now when I sample from my hw depth stencil buffer and then convert it the way you described it, it just gives me a grey screen.




Edit: Ah it does work it was my projection matrix that was wrong somehow.
Thanks for the solution !

Edited by lipsryme, 01 September 2012 - 01:48 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS