Search Unity

Sub Mesh Mask per Particle

Discussion in 'Visual Effect Graph' started by AaronAteo, Feb 19, 2020.

  1. AaronAteo

    AaronAteo

    Joined:
    Sep 11, 2019
    Posts:
    7
    For a VFX Graph, I want to output random meshes and tried to play around with the Sub Mesh Mask option of a Output Mesh block. While I was able to input per-component values, I got errors as soon as I entered per-particle-values (like a Random PerParticle, age attribute or texIndex attribute node).

    ...Exception while compiling expression graph: System.InvalidOperationException: Unable to compute CPU expression for mapping : subMeshMask...



    I guess its by design that an output block can only render a single selection of meshes for all the particles?

    The only workaround that I came up with was to duplicate the output node, set the Sub Mesh Mask manually and randomly scale the outputs to hide all but one.

    Any insights on this?
     

    Attached Files:

    Last edited: Feb 19, 2020
  2. JulienF_Unity

    JulienF_Unity

    Unity Technologies

    Joined:
    Dec 17, 2015
    Posts:
    326
    Hi,

    You cannot have different meshes per particle in a single output at the moment. This is something that we are currently looking at.

    One thing you can do is have several outputs for one system and set the alive attribute in output to show/hide per particle. But be aware that this is a workaround and not the optimize way to do it (You will still pay the cost of culled particle in outputs)
     
  3. AaronAteo

    AaronAteo

    Joined:
    Sep 11, 2019
    Posts:
    7
    Thank you for the swift clarification!
    I went with your proposed workaround for now. It didn't negatively impact performance too much so far.
     
  4. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    Any updates on this? I'm trying to animate the mesh of a particle by playing through different submeshes
     
  5. GeorgeAdamon

    GeorgeAdamon

    Joined:
    May 31, 2017
    Posts:
    48
    +1
    Any updates on this ?
    This is quite crucial if one want to switch between a large number of different meshes (.i.e having 24 copies of the output block isn't practical )
     
  6. GeorgeAdamon

    GeorgeAdamon

    Joined:
    May 31, 2017
    Posts:
    48
  7. Marie_G

    Marie_G

    Unity Technologies

    Joined:
    Mar 9, 2021
    Posts:
    76
    Hello, In unity 2021.1 (available in the unity hub) you can add up to 4 meshes on a particle mesh output and use the Mes Index nodes to create mesh changes behaviors, like a randomization for example.
    upload_2021-6-23_10-38-33.png
     
    dstrictxrlab, Frump and narranoid like this.
  8. adiserb19

    adiserb19

    Joined:
    Aug 28, 2019
    Posts:
    4
    Hello, that feature is welcomed indeed. But what about the sub-mesh mask. Would it be possible to manipulate the sub-mesh mask per particle at runtime in any way? Let's say someone would use this to hide parts of a particle geometry. Sure, it can be done with different output but could it be done any other way?

    Something like this: (use the sub-mesh mask to hide bits from the geometry)

    Capture.PNG

    edit: Also, I found out that there is a seemingly arbitrary limit on how many outputs a particle can have before "System.InvalidOperationException: Too many contexts that use particle data" is thrown. So I can't go too crazy with those either.
     
    Last edited: Nov 1, 2021
  9. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    [I haven't tested it] Cant you just create custom attribute or use existing (but not used) one like texindex to plug it as sub mesh mask?
     
  10. adiserb19

    adiserb19

    Joined:
    Aug 28, 2019
    Posts:
    4
    Nope, does not seem to work. It throws an exception and shows me a message like this:

    Untitled.png
     
  11. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Currently no, it's the same limitation as using per-particle meshes (besides the Multi-Mesh feature @Marie_G mentioned here).
     
  12. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    Oh right, dumb of me... GPU must have mesh loaded beforehand.
    Not sure what exactly you need, but instead of hiding sub meshes in vfx system what if you modified referenced mesh - you would combine or modify mesh in C# (or maybe compute shader can do this?).
     
  13. adiserb19

    adiserb19

    Joined:
    Aug 28, 2019
    Posts:
    4
    Well, I wanted to use a point cloud to feed sub-mesh masks to each individual particle. The idea was to disable parts of a already split mesh to chop trees in a vegetation system, for example. So whatever the solution is, it must be able to work per instance. I could use multiple outputs instead, but it's not too pretty or efficient.
     
  14. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    If 4 meshes are enough for you, then you can use the MultiMesh feature we discussed and set the MeshIndex attribute per particle.

    Alternatively, in 2021.2 onwards you can use the new ShaderGraph refactor for the VFX Graph and do your tree chopping logic in the shader (for example, you should be able to vertex-color the different submeshes, and then just collapse their vertices to (0,0,0) when that particular submesh needs to be disabled by feeding some per-particle value from the VFX Graph).
     
    Qriva likes this.
  15. adiserb19

    adiserb19

    Joined:
    Aug 28, 2019
    Posts:
    4
    Yeah, that might be an option as well.
     
  16. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    2024 - still waiting for this feature...

    Can't imagine putting a check in the vertex shader and outputting "position.w = -1" if it fails is such a big deal.
     
    Last edited: Feb 27, 2024
  17. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    As stated above, If you need per-particle Mesh variation you can use the Mesh Count option in the Inspector which allows you to have 4 meshes variation. You can find more information about Submeshes and MeshCount in this thread.

    If you require more than 4 per-particle meshes variation, one workaround would be to use several outputs.
    But as mentioned, it's a workaround. We should extend and improve the MeshCount usage.
    Have a great day

    upload_2024-2-28_14-48-12.png
    upload_2024-2-28_14-48-24.png
     
  18. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    @OrsonFavrel I ended up writing a custom shader, where I set position to zero if conditions are not met. Meshes are distingueshed using vertex color