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

Procedural Generation Of A Point Cache For Vfx Graph

Discussion in 'Graphics Experimental Previews' started by JakHussain, Apr 10, 2019.

  1. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    I have some simulation data which results in 100,000s of positions and colours which is exactly what the morphing face demo from the VFX samples uses from the point cache. The graph doesn't necessarily need the point cache itself just the attribute maps for position and colour which I have arrays for in C#.

    It looks like the attribute maps themselves in the graph are designed to take a texture 2D but when I pass in random textures instead of the positions from the point cache the results look nothing like the images. What type of image do I need to pass in to be able to control the positions and colours of the resulting graph?

    Ideally I can just reference the visual effect component, pass in 2 textures that I generate in runtime and then get my expected output rendered.
     
    Chmyke likes this.
  2. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    703
    To mimic how the VFX Graph is reading a point cache but from a texture, you'll have to :
    - Create the texture in RGB (or RGBA) float format.
    - Set the texture to have no mip maps, clamp, and no interpolation.
    - Do you own node logic to convert a point index to a UV coordinate to sample the correct pixel in the texture.

    I already did something like that, and here's the part of my graph that you're interested in :
    upload_2019-4-11_8-44-27.png

    - Data Width and Data Height are the Width and Height of the input texture.
    - Position_Index is my map (it contains a position in XYZ and a color index in A)

    And I use the particle ID as point index source.

    Hope that will help you !
     
  3. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    Hi Remy, this is great and it's good to know I was heading in the right direction. I just want to clear up a couple of things though:

    So the texture's rgb values need to represent the xyz values of my position array and the alpha channel is supposed to contain my color index but what actually is that? Is the index supposed to just be integers increasing from zero or will I need to assign more specific values to align my positions texture to my colors texture?

    I assume the colors texture will simply contain the rgb values I want but does the alpha channel represent anything special when it comes to a color attribute map like with the position? Or just normal transparency?

    Finally, the float values stored within my position texture, do they need to be normalized between zero and one like with colors or can I store the true world space positions that I want in the texture?
     
    MuchoBestoStudio likes this.
  4. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    Oh an one last thing, your screenshot cuts off before the sample texture 2d node feeds into your main graph. What block are your final s and w properties feeding into?
     
  5. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    Bumping this thread. I know procedural point cloud rendering with millions of particles is exactly what's needed in engineering fields and I'm sure many more people besides myself could benefit from learning how to do this but I don't quite understand the full picture.
     
  6. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    Last edited: Apr 15, 2019
    JakHussain likes this.
  7. Koaleo

    Koaleo

    Joined:
    Jul 13, 2015
    Posts:
    2
    Hello,
    any news about how to use the output of the graph above? Where do I have to plug in s and w?
    Thanks a lot
     
  8. narranoid

    narranoid

    Joined:
    Nov 16, 2018
    Posts:
    1
    This post is a little old right now, but I managed to find out some time ago how Remy's node setup is supposed to be used.
    I created a video on how to combine 2 point caches and interpolate between them to demonstrate that:


    To briefly answer an issue I think most people have with Remy's screenshot:
    The texture put in the SampleTexture2D node is the attribute map of the point cache and the data width and height equal the square root of the point count, because you can see a point cache kind of like a square texture.

    If you want to know more about the details, I encourage you to watch the video, as it is a little difficult to explain without example content.
     
    Noisecrime, valarnur and JakHussain like this.
  9. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    703
    Thanks @narranoid for this video ! This thread went totally under my radar and I didn't help back people, sorry :(
     
    narranoid likes this.
  10. ctedin187

    ctedin187

    Joined:
    Aug 20, 2018
    Posts:
    11
    I've had some success getting a switchable number generator in the VFX graph. I have had some trouble, however, getting the effect to work cleanly. The point caches create really clean numbers, but using the setup from above (thank you SO much for that work, by the way) produces some odd results. Any idea how to clean this up a bit more? Some numbers are worse than others.
    upload_2020-8-5_10-53-48.png
     
  11. Ragueel

    Ragueel

    Joined:
    Jun 2, 2018
    Posts:
    39
    So can I create point clouds at runtime and control them with compute shaders?
     
  12. cameruption

    cameruption

    Joined:
    Feb 22, 2014
    Posts:
    1
    Very useful video + example @narranoid! One wrinkle: I'm trying to use your approach, and it works well with an un-decimated point cache (one with full dimensions, ie. 1024 x 1024 or something) but not with a decimated point cache (one that gets rid of transparent pixels). SetPositionFromMap handles this case fine. Do you have an idea of how one might extend the example to work with such a pCache?