# Reconstructing Position from Depth Data

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

## Recommended Posts

Hi! A pitty that the old thread was closed. http://www.gamedev.net/community/forums/topic.asp?topic_id=506573 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 on other sites
You need an inverse of the View*Projection matrix,
// Get world position of this pixel by using the inverse of the ViewProj matrix and the depth	float4 worldPosition;	worldPosition.x=input.texcoord.x*2.0f-1.0f;	worldPosition.y=-(input.texcoord.y*2.0f-1.0f);	worldPosition.z= depth;	worldPosition.w=1.0f;	worldPosition=mul(worldPosition,invViewProj);	worldPosition/=worldPosition.w;

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

##### 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.xyz /= 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)

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 10
• 16
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632928
• Total Posts
3009271
• ### Who's Online (See full list)

There are no registered users currently online

×