- Home /
How to multiply two vector4
In the shader you can to that simply like this for example.
// A, B and C are half4
half4 D = A.xxyy * B.xxyy * C.xyzw;
But how to convert this in C#. It seems that we can't multiply vector4.
Answer by MaT227 · Jul 02, 2013 at 03:55 PM
It seems that the Vector4.Scale is the good choice !
Yes, this works, but doesn't quite give you what you asked for in that it always multiplies each component against the same component in the second vector. If you need more flexibility, as implied by the sample code in your question, then you can create your own function as I indicated in my answer.
Answer by Dave-Carlile · Jul 02, 2013 at 03:53 PM
You can create a new Vector4
by multiplying the components you're interested in...
Vector4 v1 = new Vector4(1, 2, 3, 4);
Vector4 v2 = new Vector4(2, 3, 4, 5);
Vector4 v3 = new Vector4(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w);
Not the prettiest, but it works. Create a static method to do it for you.
Answer by dorpeleg · Jul 02, 2013 at 03:52 PM
See this: Vector.Multiply
Just a quick google and you can find anything.
That's for WPF. It is completely unrelated to anything on these forums.
Apparently your googling skills aren't as honed as you thought :)