Sign in to follow this  

Reconstructing Position from Depth Data

Recommended Posts

Hi! A pitty that the old thread was closed. I found a shader code and the line that got my attention was: float4 pos = mul(ScreenToView, float4(InPosition.xy, 1, 0)); Now with all the calculations floating around I wonder how they are doing this with just a matrix. It's nice and efficent. (At least for the Gpu) I guess it's pretty basic for some of you but maybe you can explain me what they are doing there as I have no clue how to build such a matrix and I'm always open to improve my already to slow shader codes. :) Regards

Share this post

Link to post
Share on other sites
You need an inverse of the View*Projection matrix,
than in the pixel shader:

// Get world position of this pixel by using the inverse of the ViewProj matrix and the depth
float4 worldPosition;
worldPosition.z= depth;

EDIT: Oh, you want the matrix... sry, dont know that

Share this post

Link to post
Share on other sites
I'm not seeing that exact line anywhere in that thread but it looks like you're talking about what wolf posted in the OP:

FLOAT4 worldPos4 = mul(FLOAT4(screenPos, 1.0f), WorldViewProjInverse); /= worldPos4.w;

Like neXus said this is just taking a projected coordinate, and multiplying it byt the inverse of view * projection to get a world-space coordinate. It certainly works, however there are more efficient ways to reconstruct position (which you'll see we talk about if you keep reading through that thread)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this