Search Unity

Issue implementing Translation matrix in ShaderGraph

Discussion in 'Shaders' started by Demkeys, Feb 23, 2019.

  1. Demkeys

    Demkeys

    Joined:
    Nov 14, 2014
    Posts:
    32
    I've been learning about Translation, Rotation and Scaling matrices. I tried to implement them in ShaderGraph. Rotation and Scaling worked fine but I ran into an issue with the Translation matrix. This is the shader I made:
    screencap2.png
    The result of this should be that the vertices have a sort of back and forth motion on the Y axis, but that doesn't happen. The weird thing is that I could've sworn this was working earlier, and suddenly stopped working. It is very much possible that I made some changes somewhere in between an just forgot about those changes and that's what caused the problem. But I'm now confused as to whether this is a mistake in my calculation, or a bug in ShaderGraph.
    Anyone know what's going on?
     
    Last edited: Feb 23, 2019
  2. Demkeys

    Demkeys

    Joined:
    Nov 14, 2014
    Posts:
    32
    UPDATE: After doing more research I figured out what was wrong. Definitely not a bug in Shader Graph. This was a mistake in my calculation, due to a fundamental misunderstanding of how Matrix multiplication works. I recently learned about Matrix multiplication and jumped the gun a little lol. The issue was with the order in which I was multiplying the Translation Matrix and the Vector.
    screencap3.png
    This is what the calculation should have been. One of the rules of Matrix multiplication that, if I had done more research on Matrix multiplication then I would have found, is this:
    screencap4.png
    So in this case apparently the order matters. So 4x4 * 4x1 is not the same as 4x1 * 4x4. I should have been multiplying 4x4 * 4x1. Well, learned something.
    Anyways hope this helps anyone else who runs into a similar issue.
     
    Kondziu2504 and VirtualPierogi like this.