I'm creating a primarily 2d game (platformer perspective) with 2d background parallax layers. The parallax effect falls out of the fact that I'm positioning a bunch of layers in 3d and using a perspective camera. I'm using Unity which has a left-handed coordinate system with camera pointing down positive Z (positive X rightwards, positive Y is upwards).

I'd like to occasionally apply an effect that "artificially raises up" the parallax layers in the background. So that the layers further into the background increase their Y position as their Z position increases. Hopefully this diagram makes it clear:

Diagram of parallax layers

How would I construct a 4x4 matrix that I could multiply by my usual perspective matrix in order to produce this effect? (Is it calling shearing?) I thiiink (but I'm not 100% sure without seeing it) that I want the Y change of each layer in screen space to be proportional to 1/z.

(Note: I realise I could fake this by moving the background layers directly but I'd like to avoid that if possible!)

  • $\begingroup$ I wouldn't say that moving background layers directly is in any way "faking" unless you have specific reason to say so. I assume that parallax scrolling layers are just sprites/images, so by moving their transform, you're not modifying game logic and you're not changing colliders in any way. Most, if not all, Unity tutorials will deal with parallax scrolling by moving object transform in certain direction. Here is example from my freelance project - youtu.be/m28Ehta2CoA?t=62 - I am only modifying transform in background object to simulate driving car. $\endgroup$ Commented Aug 14, 2020 at 6:44

2 Answers 2


I belive what you are looking for is a scale Matrix, or actually it will end upp with as a shear matrix for you.

Usually they look like this

Sx  0   0   0
0   Sy  0   0
0   0  Sz   0
0   0  0    1

If you have no scaling, Sx, Sy, Sz represent the scaling in corresponding dimension. So put the to 1 for no scaling.

But now you want to scale the height depending on the z value. So we want to modify it abit. If you would put Sx, Sy, Sz to the value one. And the put a higher value than one on Syz, then it would scale the height (Y), the futher away you are.

Sx  0    0   0
0   Sy  Syz  0
0   0   Sz   0
0   0   0    1
  • $\begingroup$ Oh this is a great answer, thanks! After reading your answer I realised something else. If you think of the 3 columns as the basis vectors for an affine transform, then by changing that Syz, it pulls the Z axis upward. That makes a lot of intuitive sense to me. $\endgroup$ Commented Sep 17, 2020 at 15:52
  • $\begingroup$ Glad I could help! You are welcome! $\endgroup$
    – the1bird
    Commented Sep 17, 2020 at 18:20

I think all you have to do is to transform the back layers in the Y axis. FYI, a shear means to bend an object, see image bellow:



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.