Search Unity

Question Rotate a mesh and then independently use angular velocity

Discussion in 'Visual Effect Graph' started by fleity, Nov 10, 2022.

  1. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    Hi everyone,

    how would you approach this problem because it seems super but it's certainly more than an inconvenience:

    I have a cone shaped mesh, opening pointing upwards (like a V) I would like to rotate this so it points along the local Z axis of the vfxgraph visual effect.
    Set/Add Angle x -90 does this (like this <)
    nice.

    now I want to keep rotating this mesh around the emitter z axis, but angular velocity basically is now gimbal locked and rotates it around the same axis on y and z.

    upload_2022-11-10_12-15-56.png


    I tried moving the set angular velocity to the Initialize context and the add -90 Angle into the Output Context and hoped that it would only add the angle for the rendering, but that creates the same result as doing it all in Initialize.


    I could duplicate the mesh to achieve this, but the instead of one cone I have 6 in the project and that doesn't seem right at all.

    upload_2022-11-10_12-20-14.png

    what am I doing wrong?
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
  3. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    Did the Thread linked by @Qriva helped ?
    If not don't hesitate to say so and will try to take some time to help you.
     
  4. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    @fleity , in your case I think that you can just use the" orient block" in Advanced mode.
    You setup your Initial Angular velocity in the initContext, and Use the OrientBlock to properly "orient"your Cone.

    Don't mind the Gif popping... It's just a bad loop.
    Unity_jZ1PSSTfHT.gif
    upload_2022-11-14_11-4-28.png
     

    Attached Files:

    fleity likes this.
  5. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    Thanks a bunch @OrsonFavrel for clarifying. Yes orient advanced works as expected :)
    I somewhat expected this to a feature of the initialize context because the order of the steps that needed to happen in my brain was first orient, then rotate. And then even when I flipped that around I used the same nodes, resulting in the same outcome. Should have thought of using orient instead.
    One more question though. In terms of performance is there a major difference in using the orient block to do this vs. not needing the orient block at all because the mesh is modeled facing the correct direction? (not for 1-10 particles sure, but lets say for a significant number?)
     
  6. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    Well I suggested the "OrientBlock" as I thought that you might need to orient them down the road...
    But if not..
    You can manually set the "Axis attribute" in the InitContext.
    So in your case you can Swap the Y/Z axis and still add some angular on the Y axis.
    This way you can get rid of the "Orient Block".
    upload_2022-11-14_12-43-3.png

    About optimization:

    Here is the Code done by the Orient block in "advanced mode":
    Code (CSharp):
    1.  
    2. axisX = normalize(AxisX);
    3. axisZ = normalize(cross(AxisX, AxisY));
    4. axisY = cross(axisZ, axisX);
    5.  
    You can see what a block is doing by looking into your Preference settings > Visual Effect > Show Additional Debug Info. After this when you select a Block , you should have more information about what the Block is doing and the Computed Source Code:
    upload_2022-11-14_13-6-58.png

    upload_2022-11-14_13-8-25.png


    With that being said, while it can be interesting to save some operations, sometimes it's better to save "Memory".
    When doing operations in the "InitContext" or "Update", the calculation is done per-particles and attributes values saved in Memory. Those need to be Loaded to Draw the Quad/Mesh. You can have more information in this Thread.

    When doing operation in the "Output Context" calculation is usually done per-vertex, no attributes are stored and values can be used directly to Draw.

    In your case, the second method will make you store 3 Vector3 attributes (Axis-X, Axis-y, Axis-Z) and get rid of some Cross-Product and Normalize operations.
    So ... It depends on other factors, like the others calculations , the number of particles etc...
    I would suggest you to profile cause in the end it really depends on your situation.

    Hope this help a bit and that it's not too confusing.
    Have a great day.

    Unity_XzFSHpk8Lg.gif
     

    Attached Files:

    Qriva likes this.
  7. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    Makes perfect sense and thanks very much for the insight.
    Nice to see both approaches can work. 130% answered all of my questions :)
     
    OrsonFavrel likes this.