<blockquote>
  <p>clip(divide by w) -> screen space</p>
</blockquote>

<p>Be careful, if you're really in screen space. My guess is, you're doing picking or deferred rendering, in which case you're probably reading fragments in Normalized Device Space (i.e. x and y in range <code>[-1, 1]</code>*).</p>

<p>If so, you can do it like this:</p>

<p>Read out Normalized Device Coordinates as <code>vec4</code> with depth as z value and <code>1.0</code> as w value and bring them into <code>[0, 1]</code> range by multiplying by <code>2</code> and subtracting <code>1</code>.
Convert them into Eye Space with the inverted projection matrix.
Divide your new vector by its <code>w</code> coordinate (which is your undivide step). Now you're in Eye Space.</p>

<p>There are more ways to do this, you can have a look at <a href="https://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/" rel="nofollow noreferrer">Reconstructing Position From Depth</a> to dive further into how.</p>

<p>*I'm assuming OpenGL, ranges might be different in DirectX</p>

CC BY-SA 3.0
2018-01-08T08:18:21.850Z
2018-01-08T08:18:21.850Z
Tare
<p>Object Space → World Space → Eye Space → Clip Space → Normalized Device Space → Window Space</p>

<ul>
<li>You get from Object Space to World Space by multiplying by the "World
Matrix" (This may actually be multiple matrices depending
on the parent-child object hierarchy of the scene.  Compose them all together to get a single "World Matrix" for a given object.)</li>
<li>You get from World Space to Eye Space by multiplying by the "View Matrix".</li>
<li>You get from Eye Space to Clip Space by multiplying by the "Projection Matrix".</li>
<li><p>You get from Clip Space to Normalized Device Space by performing the "perspective divide" (divide by w in clip space coordinates).  <strong>This is a non-linear transformation</strong> requiring a divide, and is not represented by a matrix.  <strong>Information can be destroyed in this step.</strong>  If w is divided by w you just get 1, and there's no way to recover the original w.</p>

<p><a href="https://i.sstatic.net/PqSr6.png" rel="noreferrer"><img src="https://i.sstatic.net/PqSr6.png" alt="Divide by w"></a></p></li>
<li><p>You get from Normalized Device Space to Window Space by performing the Viewport and Depth Range transform. (Simple linear relationship)</p>

<p><a href="https://i.sstatic.net/xGOwn.png" rel="noreferrer"><img src="https://i.sstatic.net/xGOwn.png" alt="Viewport Transform"></a></p>

<p><a href="https://i.sstatic.net/vVEX9.png" rel="noreferrer"><img src="https://i.sstatic.net/vVEX9.png" alt="enter image description here"></a></p></li>
</ul>

<p>The World Matrix, View Matrix, and Projection Matrix are all just 4x4 matrices and can be inverted to get the reverse transformation.</p>

<p>So, to go backwards...</p>

<ul>
<li>You get from Window Space to Normalized Device Space by performing the inverse of the Viewport and Depth Range transform.</li>
<li>You can get from Normalized Device Space to Clip Space by performing the inverse of the perspective divide (multiply by w).  <strong>This is a non-linear transformation</strong> requiring a multiply, and is not represented by a matrix.  In general this operation doesn't magically recover 3D data from 2D data.  You must know something about the depth externally to be able to recover the 3D position of a point on the 2D screen.</li>
<li>You can get from Clip Space to Eye Space by multiplying by the inverse of the "Projection Matrix"</li>
<li>You can get from Eye Space to World Space by multiplying by the inverse of the "View Matrix".</li>
<li>You can get from World Space to Object Space by multiplying by the inverse of the "World Matrix".</li>
</ul>

<p>May I suggest reading <a href="http://www.songho.ca/opengl/gl_transform.html" rel="noreferrer">this explanation of the OpenGL Transformation</a>.</p>

CC BY-SA 3.0
2018-01-09T17:19:57.720Z
Just want to point out that you *sometimes* see projection matrices that are singular, but the OP says this isn't case in his example.
Simon F
CC BY-SA 3.0
2018-01-09T18:21:45.163Z
True, @SimonF, such is the case for an orthographic projection matrix.
Wyck
CC BY-SA 3.0
2018-01-08T17:03:19.327Z
2018-01-08T17:03:19.327Z
Wyck
<p>I'm trying to figure out how to reverse Eye space -> projection -> clip(divide by w) -> screen space conversion.</p>

<p>Basically, I want to get Screen space (still have z value for z-buffer) -> undivide? by w -> inverse projection. </p>

<p>I found the inverse matrix for projection but can't figure out how to get the coordinate "undivided" by w.</p>

<p>Thank you!</p>

CC BY-SA 3.0
2018-01-08T17:07:27.233Z
The OpenGL wiki has a great explanation of the process: https://www.khronos.org/opengl/wiki/Compute_eye_space_from_window_space
bernie
<matrix>
Screen space coordinates to Eye space conversion
hans-1795
# Screen space coordinates to Eye space conversion

(Asked by: username_0 on 2018-01-07)

I'm trying to figure out how to reverse Eye space -> projection -> clip(divide by w) -> screen space conversion.

Basically, I want to get Screen space (still have z value for z-buffer) -> undivide? by w -> inverse projection.

I found the inverse matrix for projection but can't figure out how to get the coordinate "undivided" by w.

Thank you!

**Tags:** matrix

> **Comments:**
> **username_1**: The OpenGL wiki has a great explanation of the process: https://www.khronos.org/opengl/wiki/Compute_eye_space_from_window_space  

---

## 2 answers

### Answer by username_3 on 2018-01-08. Score: 5 | Accepted answer

Object Space → World Space → Eye Space → Clip Space → Normalized Device Space → Window Space

* You get from Object Space to World Space by multiplying by the "World
  Matrix" (This may actually be multiple matrices depending
  on the parent-child object hierarchy of the scene. Compose them all together to get a single "World Matrix" for a given object.)
* You get from World Space to Eye Space by multiplying by the "View Matrix".
* You get from Eye Space to Clip Space by multiplying by the "Projection Matrix".
* You get from Clip Space to Normalized Device Space by performing the "perspective divide" (divide by w in clip space coordinates). **This is a non-linear transformation** requiring a divide, and is not represented by a matrix. **Information can be destroyed in this step.** If w is divided by w you just get 1, and there's no way to recover the original w.

  [![Divide by w](https://i.sstatic.net/PqSr6.png)](https://i.sstatic.net/PqSr6.png)
* You get from Normalized Device Space to Window Space by performing the Viewport and Depth Range transform. (Simple linear relationship)

  [![Viewport Transform](https://i.sstatic.net/xGOwn.png)](https://i.sstatic.net/xGOwn.png)

  [![enter image description here](https://i.sstatic.net/vVEX9.png)](https://i.sstatic.net/vVEX9.png)

The World Matrix, View Matrix, and Projection Matrix are all just 4x4 matrices and can be inverted to get the reverse transformation.

So, to go backwards...

* You get from Window Space to Normalized Device Space by performing the inverse of the Viewport and Depth Range transform.
* You can get from Normalized Device Space to Clip Space by performing the inverse of the perspective divide (multiply by w). **This is a non-linear transformation** requiring a multiply, and is not represented by a matrix. In general this operation doesn't magically recover 3D data from 2D data. You must know something about the depth externally to be able to recover the 3D position of a point on the 2D screen.
* You can get from Clip Space to Eye Space by multiplying by the inverse of the "Projection Matrix"
* You can get from Eye Space to World Space by multiplying by the inverse of the "View Matrix".
* You can get from World Space to Object Space by multiplying by the inverse of the "World Matrix".

May I suggest reading [this explanation of the OpenGL Transformation](http://www.songho.ca/opengl/gl_transform.html).

> **Comments:**
> **username_4**: Just want to point out that you *sometimes* see projection matrices that are singular, but the OP says this isn't case in his example.  
> **username_3**: True, @username_4, such is the case for an orthographic projection matrix.  

---

### Answer by username_2 on 2018-01-08. Score: 0

> clip(divide by w) -> screen space

Be careful, if you're really in screen space. My guess is, you're doing picking or deferred rendering, in which case you're probably reading fragments in Normalized Device Space (i.e. x and y in range `[-1, 1]`\*).

If so, you can do it like this:

Read out Normalized Device Coordinates as `vec4` with depth as z value and `1.0` as w value and bring them into `[0, 1]` range by multiplying by `2` and subtracting `1`.
Convert them into Eye Space with the inverted projection matrix.
Divide your new vector by its `w` coordinate (which is your undivide step). Now you're in Eye Space.

There are more ways to do this, you can have a look at [Reconstructing Position From Depth](https://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/) to dive further into how.

\*I'm assuming OpenGL, ranges might be different in DirectX


---

