Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

[VFX Graph] Accessing particles data in Scripts

Discussion in 'Graphics Experimental Previews' started by Ben-Kuper, Mar 27, 2019.

  1. Ben-Kuper

    Ben-Kuper

    Joined:
    Aug 31, 2012
    Posts:
    16
    Hey there,
    I'm trying to use the VFX graph to filter out and modify input particles, so I can access a reduced amount of the initial particles in scripts.

    I have a KinectV2 generating a point cloud, quite dense.
    My idea is to use the VFX graph and keijiro's base to use this point cloud in the VFX graph, do some of the heavy processing of downsampling, AABoxKill, etc. and send back to a script the filtered particles, which would allow me to do more efficient CPU processing because it would only handle the reduced, filtered positions.

    So my main question here is : is it possible to retrieve the particle data in scripts after the update context ?
    Or does it make more sense to actually use computer shaders for that ?

    Thank you
     
  2. JulienF_Unity

    JulienF_Unity

    Unity Technologies

    Joined:
    Dec 17, 2015
    Posts:
    328
    Hello,

    There is no way to readback particle data to CPU at the moment. This is something that is planned in the future.
    Also accessing particle buffers from GPU in a external compute shader is not yet there but may come soon.
     
  3. Ben-Kuper

    Ben-Kuper

    Joined:
    Aug 31, 2012
    Posts:
    16
    Ok thanks,
    so basically I should just use compute shaders to do all the heavylifting and then go back to CPU (maybe some ECS then do to clustering ?)
     
  4. headlessstudio

    headlessstudio

    Joined:
    Feb 25, 2016
    Posts:
    83
    Any news on this?
     
  5. tcmeric

    tcmeric

    Joined:
    Dec 21, 2016
    Posts:
    190
    Hi, also looking for this. Looking to get the particle position on die event.
     
  6. Moferad

    Moferad

    Joined:
    Dec 16, 2015
    Posts:
    5
    Any update on this?
     
  7. Levrden

    Levrden

    Joined:
    Jan 26, 2016
    Posts:
    16
    I am working on a project for this... It is not performance friendly but it works to have some datas.
    I get my particles dying on collision, and generate a new particle on die, which color depends on its position. I have a camera with a render Texture and a script that detects the particle's color. It is not effective at all but it works. I can share it in some are interesting
     
    Stickeyd and Moferad like this.
  8. Moferad

    Moferad

    Joined:
    Dec 16, 2015
    Posts:
    5
    This would be awesome Levrden, need it for some experimentation (grabbing particle data) so it being not performance friendly is fine for now
     
  9. Stickeyd

    Stickeyd

    Joined:
    Mar 26, 2017
    Posts:
    174
    I'm super interested in that too. Can you DM with with more info?
     
    Last edited: Mar 12, 2020
  10. Levrden

    Levrden

    Joined:
    Jan 26, 2016
    Posts:
    16
    Hello sorry, i missed the answers ! For now i don't have a lot of time to comment my unity project, but i can send it !
    It is a project for making haptic gloves with arduino, so i use OSC jack from Keijiro ro get and send my datas.
    It is a hdrp 2019.3.3 project.

    The settings are :

    - There are hands controlled my leapmotion that have empty objects at the end of each finger, and on the palm. So 12 objects tracked.
    - In the hierarchy, you have the SimplePartsEmission, the VFX graph.
    -there a a lot of property hided, for all the 12 objects.
    - the script var2vfx aims to sync my incoming osc properties to the vfx properties. You can use it or not. I used to use it before the propertybinder component.
    - the propertybinder script is there to syncronize the 12 objects, the output position of the particles that depends on properties, and the position of the second camera.

    In the hierarchy, the partpos object is the output position of the articules, and inside the second camera. The camera outputs a rendertexture.

    Then, you have the OSC EventTrigger, that has a script for getting the color of the particle, and output it has a property, or a value, or whatever you need. In my script, it is in a value "col" that take the grayscale value of a pixel on the texture.

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    THE GRAPH


    To make it less messy, i have made subgraph operators and blocks.

    The principle is : When a particle is very close to one of my fingers, it changes of color and die.
    the color changes depending on the scale of the empty object the particle approches. In that way, i can know which finger has been touched.

    At the end of the update, and event trigger on death another graph that outputs a single particle in front of the second camera which inherit the color of the dead particle.


    Here is the Github : https://github.com/Levrden/LutherieNumerique-Levrden


    I hope it is clear enough. If you have any suggestions of questions, i am of course open to it !
     
  11. Stickeyd

    Stickeyd

    Joined:
    Mar 26, 2017
    Posts:
    174

    Thank you very much! Do you have any idea how to send back particle data from GPU to GPU(other shader), rather than from GPU to CPU like in your project?
     
  12. Levrden

    Levrden

    Joined:
    Jan 26, 2016
    Posts:
    16
    Of course, after getting it on the cpu, you can send it back to another gpu thread, but I assume that you don't want that...
     
  13. Stickeyd

    Stickeyd

    Joined:
    Mar 26, 2017
    Posts:
    174
    Yeah... It's very performance heavy. Any ideas how to send from GPU to GPU? That could save performance
     
  14. Levrden

    Levrden

    Joined:
    Jan 26, 2016
    Posts:
    16
    I don't see, sorry. It it the famous problem on how to get particle data, but as far as i know, it's not yet possible