   How do you unproject
  Hi normally i would use the Directx unproject function but i am trying to do this in a shader from a depth value and screen coordinates (0 -> 1). I have tried lots of different methods and not seem to be getting the right result. Can anyone help me here?I have view and projection matrices, the screen coordinates and a depth value which is taken from either of 2 ways (not sure which is best): 1) sqrt distance between the camera and the point, 2) using the Z value straight out of the position after world * view * projection matrices.Any help or advice would be appreciated.ThanksP.S: didnt post on directx forum because i dont want to use an API sepcific method.   
  I believe you just need to create the inverse of your combined view and projection transform matrix and send it to the shaders along with your regular transform matrix/matrices.  I believe most graphics APIs have a function to calculate the inverse of a matrix, so you can calculate the inverse in your C/C++/C#/whatever code and then pass it down to the shaders to do the grunt work.When you apply the inverse of the view and projection transform matrices to a screen coordinate, the result should be that you get the world coordinate.  If you want the local space of the point (if you're rendering a model or something), you can use the inverse of the world*view*projection.   ;  hi thanks for the reply, this is the code i have at the moment. I have tried a few things and all seem to have strange effects. This way is supposed to find a direction and then move along that direction by the depth read from the texture.My in coordinates are in the range -1 to 1 on x and y, 0 to 1 on depth. zMax is cameras far plane. depth distance ignores near plane.vdir.x= (  In.ScreenUV.x ) / mProj._11;vdir.y= (  In.ScreenUV.y ) / mProj._22;vdir.z = 1;vdir = normalize(vdir);float3 wPos = (vdir * depth * zMax);Am i doing something wrong or can you suggest a better way?I tried just putting back through inverse matrices but always trip up and think it has something to do with that pesky w coordinate.   ;  The (1,1) position in the transformation matrix describes how much the input X affects the output X, and the (2,2) position describes how the input Y affects the output Y.The problem is that the actual operation of a matrix transform on a vertex's X coordinate also factors in the Input Y and Z!Out.X = (In.X * _11) + (In.Y * _12) + (In.Z * _13) + _14;(or the matrix coordinate row/column notation might be backwards, but that doesn't matter for this discussion)So, unless _12, _13, and _14 are all zero, the equation "In.X = (Out.X / _11);" is completely invalid.  The only input matrix this would hold true for would be a scaling-only matrix.You really *do* need to use a inverse transform matrix to get the proper result.   ;  ok thanks i thought there was something wrong with that code. This is the way i was doing with inverse matrices but still doesnt seem to work. The position changes with the camera position for some reason and i have checked all the matrices are being linked correctly:float4 wPos = float4(In.ScreenUV.x, In.ScreenUV.y, depth , 1);wPos = mul(wPos, viewProjInverse);wPos = wPos / wPos.w;Am i doing something wrong here? I wasnt sure whether i should divide by w after inverse projection and then do inverse view but i tried both ways and it seems the same. Thanks again for your help.;  I'm not very familiar with what happens with the W coordinate on a vector4 when transforming it using an inverse matrix, since I've never unprojected on the GPU before (only on CPU, and I was using Vector3 data types).  I'm not sure if it's supposed to be 1 or 0.  Did you try 0 yet to see if that makes any difference?   ;  yeah i have tried 0 and i have put the depth through the shader too to make sure that was being read correctly and it is. Its like everything is being un projected to the same point as if the distance is 0 on all depths. Im running out of ideas.;  Me too :(   Sorry...My only suggestion at this point would be to examine every step of the algorithm to see where the numbers stop making sense...   