Search Unity

Question Matrix4x4 to position, rotate, and scale particle

Discussion in 'Visual Effect Graph' started by PraetorBlue, Jul 25, 2021.

  1. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    I'm trying to use a Matrix4x4 (which I'm getting from a graphics buffer) to position, rotate, and scale my particles:
    upload_2021-7-24_20-13-12.png
    upload_2021-7-24_20-17-30.png

    When I try this, I get an error:
    Exception while compiling expression graph: System.InvalidOperationException: The expression UnityEditor.VFX.VFXExpressionExtractAnglesFromMatrix is not valid as it have the invalid flag: InvalidOnGPU, PerElement
    . Attached the full error in a text file below.

    Is there any way to do this? It seems like maybe you can't extract position, rotation, and scale from a Matrix4x4 on the GPU for some reason?
     

    Attached Files:

  2. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    154
    Hello,

    In your case, you are facing the Euler angle extraction from a matrix which isn't supported by the GPU evaluation.
    upload_2021-7-27_10-2-15.png

    We have planned to improve the error feedback to help the user to find what is the actual issue and how to resolve it.

    Modify the particle rotation using Euler isn't always the most appropriate. Alternatively, you can directly orient a particle changing the axisX/Y/Z attributes (if you are curious about the transform computation behind the curtain, you can take a look at GetElementToVFXMatrix) but for now, you can't extract matrix columns in VisualEffectGraph.

    However, there is a workaround using the Transform operators :
    upload_2021-7-27_10-26-47.png
    matrix_synchronisation.gif
    We are aware this solution isn't ideal because it will generate useless multiply, addition or dot product on GPU for some platform. You can potentially follow the update of this public issue even if it has been closed by design, we are going to address this limitation.

    You can find the VFX and Scene I used for this sample attached to this post.

    N.B.: While doing this sample, we found an issue with the extract position when evaluated on GPU, you won't be affected if you are using "Transform (Position)" instead.
     

    Attached Files:

    Last edited: Jul 27, 2021
    VladVNeykov, PraetorBlue and Vita- like this.
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Thank you so much for the detailed explanation and workaround Paul. I'll give it a shot!