Search Unity

Question Transform, matrix and direction manipulation

Discussion in 'Visual Effect Graph' started by Qriva, Nov 16, 2022.

  1. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    I feel like I'm running out of tools again. I am going to describe what I try to do, but I would like to use it as example for the wider context to reforge it into feedback.

    upload_2022-11-16_1-22-24.png

    The goal is to spawn burst of particles towards certain direction with some randomization. To do this I used cone, however I want to change cone direction every time spawn event fires. This can be done mainly with two methods:
    1. Send event attributes (position + direction), inherit them and use to construct transform with LookAt.
    2. Set some 'Transform' graph property and connect it as cone transform.
    As I pointed in the other thread the LookAt has some issues when using with attributes or something like that, but let's ignore that for now. The first method could work, but the cone is not looking at Z axis, but Y and in result particle source is rotated by 90 deg on X. If there were quaternions or easy to use matrixes this could be solved by adding quaternion with shiften rotation, but there are no quaternions or transform multiplication or anything like that (or I just missed something).
    I must go with the second method, but it requires the C# side to "know" that direction must be pre-rotated. This is not big deal to implement, but it breaks the interface between script and graph, script should not care what happens inside the effect, it just wants to play something here in that direction.
    If I decide to create other graph for the same "interface", everything crumbles - I get the same problem but this time rotation has additonal unneeded shift.

    If I haven't missed any simple and obvious solution, then my feedback is:
    • Implement transfrom multiplication to combine them (not sure if it's possible, haven't checked the implementation) as adding angles produces gimal lock and undesired results
    • I can't find multiplication of matrixes, multiplication has no such function
    • Add node to create transform from matrix, even if I pass matrix to the graph I can't feed it to the transforms
    • If possible add matrix * transform multiplication, but with transform as output
    • Fix LookAt
    • I have feeling that adding quaternion type would not be bad idea. This is big task and most of the time not required, but it would be nice addition.
    • Official custom node please :D
    Let me know if I mixed something!
     
  2. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194

    Morning :)


    First, thanks for your detailed Feedbacks.

    To be fully transparent my math skills need to be level-up, so I might not be the best person to help you but I will talk to the devs so that they can give you better information on our Math's Operators.

    I 've been facing similar issues in the past and by talking with the devs we agreed that some love was needed towards Math operators.

    -Regarding Matrix Multiplication , I think that you can use the "Transform (Matrix)" Block but from what I've understood, there might be some issues with the Space.

    -The “Custom Node” is being worked on but I can't give you any ETA.

    Now, I’ve wanted to do the same kind of VFXG with a random Direction that drives a “Cone Shape” for Impact VFX.
    This is a “solution” that I’ve been using that use "LookAt":

    upload_2022-11-16_10-55-55.png
    Here I've got a Random Directionr each Loop, but you can replace this with an Exposed Direction that will be set by Script.
    Unity_gCESkucrqy.gif
    Unity_ZK0mMaKYWy.gif

    Not sure this help :(, but as I said I will ask someone with better Knowledge of Math and the VFXG Math operator to jump in this thread.
    Have a great day and see you in the next thread or later down this one :D.
     
    Qriva likes this.
  3. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    Also, do you think that being able to have a "Shape Direction/alignment" method where the user choose the Shape Forward/up Vectors would be useful (as an alternative to the Angle) ?
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    Hi, thank you for the answer. I am on 2021.3.10 and connecting exposed property or attribute to LookAt produces error mentioned in the other thread, otherwise swapping axes with cross product would be viable solution as roll does not matter for cone.
    I did not try to use it, because it's not possible to use it. The output of this block is matrix and it can't be plugged to transform. Well, I guess it's simple TRS matrix, so position and rotation could be extracted from columns, but there is no tool to do that - there is no way to read columns, rows or anything. This is why I asked for "the same" node, but with transform output if possible.
    The angle is user friendly and as long as we operate in world / local space there is no problem with that. The problem starts when you need some transformation and angles are not driven by user. Transform component solves this problem quite well, user operates on friendly angles, but there is quaternion underneath.
    It looks like it should not be needed as there LookAt in theory, I think it would be enough if matrix/transform operations were more polished (but I am not math expert too :D).
     
  5. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    Are you talking about this :
    Exception while compiling expression graph: System.InvalidOperationException: The expression UnityEditor.VFX.VFXExpressionExtractAnglesFromMatrix is not valid as it have the invalid flag: InvalidOnGPU, PerElement


    If, so plugging an exposed property should work. The attribute "Direction" won't work in the LookAt ,as "Direction" attribute is Per-Particle. But an Exposed Property should work and is actually working on my side.
    I will try in 2021.3.10
    upload_2022-11-16_14-52-52.png

    Actually you should be able to plug Matrix in Transform and Transform in Matrix....
    upload_2022-11-16_14-55-5.png
    I remember @PaulDemeulenaere explained me some workaround about using Matrix in Transform and Transform in Matrices....
    But my monkey Brain wasn't able to process it..

    But, yeah, Math operators needs some polish.
     
    Qriva likes this.
  6. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    Correction, this is weird. If I understand this correctly it throws error when retriving angles, but I am pretty sure I tried to use whole transform and it was the same. Now I am not sure if this is some ghost bug showing up in certain situation or I just did mistake.
     
  7. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    OH. It's embarrassing. Again I am not sure if I bugged the UI in some way and it was not possible, or I was so tired and haven't even tried to connect them like this. For now let's assume it's my mistake - if I somehow manage to bug it like that I will let you know.

    By the way what is the reason angles cannot be accesed from LookAt? @PaulDemeulenaere
     
  8. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    I think that it doesn't matter if you connect the whole "Transform" or only the Angle.
    The issue (if i'm correct...) is the "extractingAngle" part of the "LookAt" runs on CPU and won't accept any Data that can change Per-particle.
    So you can use Exposed Property, Vector3 etc as input for the LookAt but you can't use Particle Attributes.
    This is due to performance considerations, but we could put a Warning (Careful what you're doing will cost an arm.) instead of an error.
     
  9. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    No no - that's the thing xD
    Right now this one compiled and works: upload_2022-11-16_15-25-5.png
     
    OrsonFavrel likes this.
  10. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194

    Tested on my side, plugging the Full Transform is working.
    I've been talking with the VFXGraph team and that's what they told me:

    The "LookAt" operator calculates a Matrix but outputs a Transform.
    Transform and Matrix are considered the same by the GPU (Float4x4).
    So passing the "LookAt '' Transform is working, but passing only the Angle and/or Scale requires to "Extract" that data from the Matrix. Extracting this data needs operations that are currently prevented on the GPU (for Perf consideration).

    I hope this helps shed some light on the LookAt operator.

    I need some time to digest and process that information. :confused:
     
  11. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    Ah, that actually would make sense as converting to euler angles probably requires bunch of if's and atans if I am correct.
    Anyway thank you for help, now when I know transform-matrix interactions are possible and LookAt works it should be a lot easier :D
     
    OrsonFavrel likes this.
  12. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    Glad that you're able to move on and continue your VFX.
    And I also learnt a lot thanks to your questions.