Is there a projection matrix with a perspective projection in the x direction and an orthographic projection in the y direction?

57 Views Asked by At

I'm looking for a projection matrix with a perspective projection in the x direction and an orthographic projection in the y direction, like the one in the picture, does this exist?

I tried to do that, but it didn't work,and it looks so weird.

gl_Position = projection * view * vec4(pos, 1.0);
gl_Position.z = (view * vec4(pos, 1.0)).y;

Here is projection looks like:

enter image description here

1

There are 1 best solutions below

0
Martin On

What you want to do cannot exactly be done in one matrix and requires an additional step, because of the way perspective projections work.

This link explains what happens after a vertex has been processed in the vertex shader, the relevant part for your problem being the perspective division. The output of the vertex shader is a 4-dimensional vector of which the homogeneous (w) component is used for the perspective division of all three other components (x,y and z).

Usually, in order to make this homogeneous division work for a perspective projection, the projection matrix looks somewhat like that:

|  a  0  b  0 |
|  0  c  d  0 |
|  0  0  e  f |
|  0  0 -1  0 |

Note that the w component is set to the (negative) z component of the (transformed) model coordinate. The subsequent homogeneous division in the vertex post-processing will therefore perform a perspective division.

That being said, in order to mix perspective and orthographic projection to result in some extreme anamorphic projection, you would basically go with the suggestion of @user253751 and use:

  • the entries of a perspective projection on the 1st, 3rd and 4th row of the projection matrix
  • the entries of an orthographic division on the 2nd row of the projection matrix

and after performing the multiplication in the vertex shader, you would multiply the y component of the resulting value in gl_Position with its w component before passing it into the post-processing stage.

This is effectively reverting what the post-processing stage will do in the homogeneous division for the y coordinate only, turning it into an orthographic projection for the y component.