Search Unity

Question Set matrix values via properties without a extra Vector4s?

Discussion in 'Shader Graph' started by digiwombat, Dec 10, 2019.

  1. digiwombat

    digiwombat

    Joined:
    Sep 26, 2013
    Posts:
    48
    I'm writing a sprite skew shader to replace an old one since I've moved to the Universal Render Pipeline.

    It's a simple shader but in the original I just piped the floats directly into the 4x4:

    Code (CSharp):
    1. float h = _SkewH;
    2. float v = _SkewV;
    3. float4x4 transformMatrix = float4x4(
    4.     1,h,0,0,
    5.     v,1,0,0,
    6.     0,0,1,0,
    7.     0,0,0,1);
    Now I can't figure out how to get those same properties into a matrix without creating extra Vectors, which just seems a bit wasteful:


    Thanks in advance for any pointers. I know it's a minor thing, but I'd like to avoid the extra vectors if I can.
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You could use a custom function node and have 2 input and have Matrix 3/4 Output.
    Than you can use the code like in your code example.

    upload_2019-12-12_10-23-39.png
     
    Last edited: Dec 13, 2019
    digiwombat and florianhanke like this.
  3. digiwombat

    digiwombat

    Joined:
    Sep 26, 2013
    Posts:
    48
    Thanks! That's exactly the sort of thing I was hoping was possible. :D