<p>I am trying to scale the value of the input vector along one axis depending on the value of the input vector along another axis, while leaving everything else unchanged.</p>
<p>Given (pseudocode):</p>
<pre><code>Vec4   V_in{x,y,z,1}
Mat4x4 M
Vec4   V_m = V_in * M
Vec4   V_out = V_m / V_m.w
</code></pre>
<p>I want to design <code>M</code> such that (for example):</p>
<pre><code>V_out.x == V_in.x
V_out.y == V_in.y / (V_in.x * (N - 1) + 1)
V_out.z == V_in.z
</code></pre>
<p>This example should achieve a multiplication of Y between 1 and 1/N for an input X from 0 to 1.</p>
<p>I did succeed in scaling the Y axis, but was not able to keep the other axes constant.</p>
<p>Is this possible?</p>

CC BY-SA 4.0
2024-01-13T16:10:33.103Z
Set your scales on the diagonal of M.
pmw1234
CC BY-SA 4.0
2024-01-13T16:54:01.550Z
@pmw1234 Can you elaborate? I don't understand how that would work. Which values would I use to achieve the outcome I described?
Beta Carotin
CC BY-SA 4.0
2024-01-13T17:48:51.227Z
@pmw1234 Thank you for your effort, but I think there is a misunderstanding. I do not have fixed scale values that I can set. I need the scaling of the vector to depend on itself. Like in a perspective projection matrix where the X and Y components are scaled based on the Z component (after the W divide).
Beta Carotin
CC BY-SA 4.0
2024-01-13T19:23:06.970Z
@pmw1234 I can't. I need one matrix for all vertices. This is for a rendering pipeline.
Beta Carotin
CC BY-SA 4.0
2024-01-13T20:29:49.070Z
From what you have described the approach it sounds like would work for your situation is to pass an xyz scale that is precomputed for each vertex then use it in the vertex shader.
pmw1234
CC BY-SA 4.0
2024-02-07T07:11:51.273Z
I guess you want a M that does not depend on input so that you can set M in a uniform buffer. But note that the component used for w-division has x in it, and out x is the input x. That implies the x component of V_in * M before the w-division must be second order of x. I think that is impossible for a linear operation V_in * M.
TheBusyTypist
CC BY-SA 4.0
2024-02-08T09:23:39.617Z
@TheBusyTypist That is the conclusion I reached aswell. Thank you for your effort!
Beta Carotin
<transformations><matrix>
4x4 matrix to scale only one axis depending on another axis
Beta Carotin
# 4x4 matrix to scale only one axis depending on another axis

(Asked by: username_0 on 2024-01-13)

I am trying to scale the value of the input vector along one axis depending on the value of the input vector along another axis, while leaving everything else unchanged.

Given (pseudocode):

```
Vec4   V_in{x,y,z,1}
Mat4x4 M
Vec4   V_m = V_in * M
Vec4   V_out = V_m / V_m.w

```

I want to design `M` such that (for example):

```
V_out.x == V_in.x
V_out.y == V_in.y / (V_in.x * (N - 1) + 1)
V_out.z == V_in.z

```

This example should achieve a multiplication of Y between 1 and 1/N for an input X from 0 to 1.

I did succeed in scaling the Y axis, but was not able to keep the other axes constant.

Is this possible?

**Tags:** transformations, matrix

> **Comments:**
> **username_1**: Set your scales on the diagonal of M.  
> **username_0**: @username_1 Can you elaborate? I don't understand how that would work. Which values would I use to achieve the outcome I described?  
> **username_0**: @username_1 Thank you for your effort, but I think there is a misunderstanding. I do not have fixed scale values that I can set. I need the scaling of the vector to depend on itself. Like in a perspective projection matrix where the X and Y components are scaled based on the Z component (after the W divide).  
> **username_0**: @username_1 I can't. I need one matrix for all vertices. This is for a rendering pipeline.  
> **username_1**: From what you have described the approach it sounds like would work for your situation is to pass an xyz scale that is precomputed for each vertex then use it in the vertex shader.  
> **username_2**: I guess you want a M that does not depend on input so that you can set M in a uniform buffer. But note that the component used for w-division has x in it, and out x is the input x. That implies the x component of V_in * M before the w-division must be second order of x. I think that is impossible for a linear operation V_in * M.  
> **username_0**: @username_2 That is the conclusion I reached aswell. Thank you for your effort!  

---

## 0 answers

