   [DirectX 10] Reconstructing pixel position
  Im trying to reconstruct pixel position from screen coordinates and z/w.I'm using DXGI_FORMAT_R32_FLOAT in depth buffer, and Im following the code on this blog: http://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/So I dont know why doesnt this work...(The depth buffer is MSAA.This is my shader:cbuffer cbPerFrame{float4x4 gInvViewProj;}Texture2DMS<float4,8> gDepthMap;struct VS_IN{float3 posL : POSITION;float2 texC : TEXCOORD;};struct VS_OUT{float4 posH  : SV_POSITION;float2 texC  : TEXCOORD0_CENTROID;};VS_OUT VS(VS_IN vIn){VS_OUT vOut;vOut.posH = float4(vIn.posL, 1.0f);vOut.texC = vIn.texC;return vOut;}float4 PS(VS_OUT pIn) : SV_TARGET{float depth = gDepthMap.Load(pIn.posH.xy, 0).r;float4 position = float4(0.0f, 0.0f, depth, 1.0f);position.x = pIn.texC.x * 2.0f - 1.0f;position.y = (1 - pIn.texC.y) * 2.0f - 1.0f;position = mul(position, gInvViewProj);position /= position.w;   ...}technique10 LightBufferTech{    pass P0    {   SetVertexShader( CompileShader( vs_4_0, VS() ) );   SetGeometryShader( NULL );   SetPixelShader( CompileShader( ps_4_0, PS() ) );    }}
  Just look into this thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=571943Its the third last posting, and it works just fine for me! :)   ;  Well it didnt worked, I always get (1.0f, 1.0f, 1.0f, -0.0f) as world position...[Edited by - Aqua Costa on May 24, 2010 3:33:42 PM];  hm. Maybe my code helps you more (Because i know it works):Matrix (C++):D3DXMATRIX invViewProj=(*DeferredShader->ViewMatrix) * (*DeferredShader->ProjMatrix);D3DXMatrixInverse(&invViewProj,NULL,&invViewProj);DeferredShader->GetCustomVariable(invViewProjMatrixIndex,&cm);if(cm){cm->SetMatrix((float *)&invViewProj);}(Yes, invViewProj)Mesh's pixel shader://Basic pixel shader. Sets all propertiesPS_OUT wtPixelShader(PixelShaderInput Input){PS_OUT output;//Fill the two G-Buffersoutput.Color0.rgb=GetDiffuseColor(Input);//output.Color0.rgb+=GetEmissiveColor(Input);output.Color0.a=1;//pow(GetSpecularColor(Input),GetSpecularPower(Input));output.Color1.rgb=GetNormals(Input);output.Color1.a=1;//length(Input.ViewPos)/FarDistance;output.Color2.r=Input.Pos.z; //Transformed my WorldViewProj <-----------------//output.Color2.a=1;return output;}And here is the light shader which transforms the depth to world:float3 DepthToWorld(float Depth,float2 TexCoord){float4 clipPos;clipPos.x = 2.0 * TexCoord.x - 1.0;clipPos.y = -2.0 * TexCoord.y + 1.0;clipPos.z = Depth;clipPos.w = 1.0;float4 PosWS=mul(clipPos,invViewProj);PosWS.w = 1.0 / PosWS.w;PosWS.xyz *= PosWS.w;return PosWS.xyz;//World Space};  Well, I guess I'm not using PIX correctly, because I tried many ways and none works correctly...   ;  Did you try to simply display the calculated vector? Instead of your normal scene...   ;  [mind in the box]i'm glad my code was usefull ))my first guess is why u using different texture coordinates where u should use single IN.TexCoord from the quadfloat depth = gDepthMap.Load(pIn.posH.xy, 0).r;float4 position = float4(0.0f, 0.0f, depth, 1.0f);position.x = pIn.texC.x * 2.0f - 1.0f;position.y = (1 - pIn.texC.y) * 2.0f - 1.0f;why pIn.posH.xy and not pIn.texC.x? in gDepthMap.Load(pIn.posH.xy, 0).r;try to test if u sample depth correctly[get close to some object and see if depth become darker or it will keep staying white]   ;  Load function needs absolute screen space coordinates and not texture coordinates;  Well my depth (z/w) values are always around 0.9f to 0.985f... Are this values ok?   ;  z/w if i'm not mistaken must be in [-1..1] range, so i guess they oktry doing some per pixel lighting[it's good way to test of the restored position is correct]aside from that you depth buffer texture output must contain non linear depthjust pos.z [see previous link]   