<p>I belive what you are looking for is a scale Matrix, or actually it will end upp with as a shear matrix for you.</p>
<p>Usually they look like this</p>
<pre><code>Sx  0   0   0
0   Sy  0   0
0   0  Sz   0
0   0  0    1
</code></pre>
<p>If you have no scaling, Sx, Sy, Sz represent the scaling in corresponding dimension.
So put the to 1 for no scaling.</p>
<p>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.</p>
<pre><code>Sx  0    0   0
0   Sy  Syz  0
0   0   Sz   0
0   0   0    1
</code></pre>

CC BY-SA 4.0
2020-09-17T15:52:56.633Z
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.
Joseph Humfrey
CC BY-SA 4.0
2020-09-17T18:20:13.557Z
Glad I could help! You are welcome!
the1bird
CC BY-SA 4.0
2020-09-17T00:27:18.857Z
2020-09-17T02:38:58.390Z
2020-09-17T02:38:58.390Z
the1bird
<p>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:</p>
<p><a href="https://i.sstatic.net/3LRVj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3LRVj.png" alt="sheer" /></a></p>

CC BY-SA 4.0
2020-08-17T19:49:32.320Z
2020-08-17T19:49:32.320Z
Nixcc
<p>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).</p>
<p>I'd like to occasionally apply an effect that &quot;artificially raises up&quot; 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:</p>
<p><a href="https://i.sstatic.net/xvYfH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xvYfH.png" alt="Diagram of parallax layers" /></a></p>
<p>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 <code>1/z</code>.</p>
<p>(Note: I realise I could fake this by moving the background layers directly but I'd like to avoid that if possible!)</p>

CC BY-SA 4.0
2020-08-14T06:44:53.307Z
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 - https://youtu.be/m28Ehta2CoA?t=62 - I am only modifying transform in background object to simulate driving car.
DirectX_Programmer
<3d><perspective><camera-matrix>
Shear(?) matrix projection along Z (depth) axis
Joseph Humfrey
# Shear(?) matrix projection along Z (depth) axis

(Asked by: username_0 on 2020-08-12)

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](https://i.sstatic.net/xvYfH.png)](https://i.sstatic.net/xvYfH.png)

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!)

**Tags:** 3d, perspective, camera-matrix

> **Comments:**
> **username_1**: 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 - https://youtu.be/m28Ehta2CoA?t=62 - I am only modifying transform in background object to simulate driving car.  

---

## 2 answers

### Answer by username_2 on 2020-09-17. Score: 2 | Accepted answer

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

```

> **Comments:**
> **username_0**: 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.  
> **username_2**: Glad I could help! You are welcome!  

---

### Answer by username_3 on 2020-08-17. Score: 0

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:

[![sheer](https://i.sstatic.net/3LRVj.png)](https://i.sstatic.net/3LRVj.png)


---

