Search Unity

How do Noise work in the Particle System?

Discussion in 'Editor & General Support' started by resetme, Jun 14, 2017.

  1. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    Hi guys, im trying to get my head around the partcile system noise.

    i have this image;


    so, X = 5 means how far the particle will move from 0?
    The preview, i understand that the texture is divided by 3, one for X, Y and Z.

    So if i have X, with black and white, what im suppose to see?
    The black means add +1 to the x? so it will move right, when it becomes white moves back to -1 so it goes left.
    that is from the top point of the texture until down? left to right? Or it never scan the texture at all and only read an specifc point x, to check if is white or black?

    BUT, if i have a 2d noise i do have movement with no scrolling, so they are scaning the texture.

    basicaly why this shape give me this animation?



    Is there any tutorial? because any thing i do i got random results.

    Fran
     
  2. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    The parameters are fed into an implementation of Curl Noise, which uses multiple samples from a Perlin Noise field.

    To use your example, a Strength of 5 produces Perlin Noise in the [-5,+5] range.
    Curl noise then combines 2 samples for each axis, giving you a final range of [-10,+10].

    This final value is the maximum potential units per second that any given particle may move.

    The texture is used to give you an indication of how particles will be affected by the noise. Imagine particles travelling across the noise (You are using Low Quality, where we only generate 1 axis of noise, and re-use it all directions, for fast by less "interesting" noise.) As the particles travel across the noise, a grey area means no effect, black means strong negative, and white means strong positive.

    We have a manual page here: https://docs.unity3d.com/Manual/PartSysNoiseModule.html If you think it is lacking specific information, let us know and we can improve it. We don't have any first party tutorials on it yet.

    I would advise trying to think more about how each parameter affects the shape of the noise:
    - Strength is the amount of movement
    - Frequency describes how often the particles will change direction
    - Damping ties Strength + Frequency together, so you can maintain the same overall noise shape at different sizes
    - (etc) I'm mainly just repeating the manual page here, so I'll stop :)
     
    karl_jones and resetme like this.
  4. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    I really appreciate your answer, i will read it as many times until fully understand it.

    For study purpose i end up creating my own noise and moving the particles using code writing by me. Curl noise is kinda difficult. my main idea was to move a particle using a texture shape, so if the texture have a circle, the particle move in circles, end up that is name stream particles? i found some houdini tutorials that work in ue.

    anyways, thank you again for that noob quesiton.
     
  5. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Ah yes, I think you are describing Vector Fields. It's a great technique! Good luck :)
     
  6. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    @richardkettlewell @karl_jones

    Hi Richard and Karl,

    I have another question about the noise module. I'm writing an application that requires particle simulation to be deterministic and allow for simulating to a given time (even in the past). However, when using the noise module, I'm unable to get deterministic results. Here's a quick video of what I mean:



    I've also noticed if the shape module is turned on (e.g., using Sphere emission), similar random behavior on reverse simulation happens.

    Neither the noise module or shape modules cause issues if the particle emits in local space - the shape and noise modules only seem to cause a problem in world space. I'm wondering if the noise and shape modules have any code in them that uses world space positions as part of some randomness functions that could cause this. If so, could you suggest any workarounds?

    Thank you!
    John


    For reference, this is how I'm seeking the particles:

    Class variables
    • velocityAnimation is a .anim file that stores a bunch of positions that I am using to move the world space particle systems
    • lastFrameIndex is an optimization that keeps track of the last simulated particle frame to avoid always resimulating from 0 (resimulation from 0 only happens when scrubbing backwards in time)

    Code (CSharp):
    1. private void ParticleSeek(int frame)
    2. {
    3.     if (frame != lastFrameIndex)
    4.     {
    5.         int frameOffset = frame;
    6.  
    7.         if (frame < lastFrameIndex)
    8.         {
    9.             particleSys.Clear();
    10.             particleSys.Simulate(0, true, true);
    11.             lastFrameIndex = 0;
    12.         }
    13.         else
    14.         {
    15.             frameOffset -= lastFrameIndex;
    16.         }
    17.  
    18.         float delta = 0.0333f;
    19.  
    20.         for (int i = 0; i < frameOffset; i++)
    21.         {
    22.             if (particleSys.main.simulationSpace == ParticleSystemSimulationSpace.World && velocityAnimation != null)
    23.             {
    24.                 velocityAnimation.SampleAnimation(particleSys, frame * delta);
    25.             }
    26.  
    27.             particleSys.Simulate(delta, true, false, true);
    28.         }
    29.  
    30.         lastFrameIndex = frame;
    31.     }
    32. }
    EDIT: I just saw 2017.1 has a feature that enables emit over distance for local simulations. I'm going to give that a try to see if it fixes my issue.

    EDIT 2: that didn't work either ;)
     
    Last edited: Sep 16, 2017
  7. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Hey,

    You have Auto Random Seed enabled.
    This means a new random seed is generated every time the system is restarted. Uncheck it :)

    Also, to rewind, use the Restart param in Simulate and enter the absolute playback time as the time param. Doing this means you don't need the call to Clear.

    When simulating forwards, set Restart to false, and just use the time you want to jump forwards by, as the time value.
     
    panta likes this.
  8. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    Not clearing the system totally worked! Thank you so much for the quick response. I realized I had forgot to turn off the AutoRandomSeed in script right after I posted that video, so thank you for finding the real problem despite my mistake :)

    Here's the working version:


    Any idea why Clear made a difference though? When Clearing, it seems like the shape module gets new randomness values even if AutoRandomSeed is false.
     
    richardkettlewell likes this.
  9. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I would guess that restarting the system via Simulate is the most important bit. I'm not 100% sure though :)

    Glad you got it working!
     
  10. therealpedro

    therealpedro

    Joined:
    Mar 4, 2015
    Posts:
    3
    Hi, I don't know if this is the right place for this question but well ...when i try to modify the strength of noise via script, it says Noise is not a variable ... do you know a snippet for that ? this is what i do :
    ParticleSystem.NoiseModule Noise = My_particles_System.GetComponent<ParticleSystem>().noise;
    Noise.strength.constant = 10;
     
  11. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Try: https://docs.unity3d.com/ScriptReference/ParticleSystem.NoiseModule-strength.html
     
  12. therealpedro

    therealpedro

    Joined:
    Mar 4, 2015
    Posts:
    3
    richardkettlewell likes this.
  13. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    @richardkettlewell @karl_jones

    Hi Richard and Karl,

    Sorry to bother you with another question, but the app we are building (https://www.pcworld.com/article/319...mix-the-new-tool-to-make-your-photos-pop.html) has been leading me to various dark corners of the particle system API :)

    The current issue I'm running into is for selection. I want a more accurate way to select particle systems via raycasting against the mesh created by the particle system. To do this, I'd like access to all the meshes generated by the particle system (from mesh particles, billboard particles, stretched billboard particles, etc.) and then (while the user has paused the video) generate a combined mesh filter that includes all these meshes, then create a mesh collider out of that to perform the raycasting against. Perf isn't a huge problem, since I'll only be doing this collider generation while the particle system is paused.

    Do you know of a way that I can access the particle system renderer's meshes? I basically want to access what I can see in the Scene viewport when I have "Shaded Wireframe" turned on, but I can't find an API to do that:



    I've written a prototype where I iterate through ParticleSystem.GetParticles and create billboarded meshes for each particle by hand. However, taking all the different rotations/scales/positions/nested particles/trails/etc. that the Particle System module creates into account sounds very difficult. Here's what I have so far:


    Is there an easier way via some API to access these meshes?

    Thank you very much,
    John
     
  14. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Hey,

    There is nothing currently available to do what's you're asking for.

    I can add it to our roadmap for the future.
     
  15. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    @richardkettlewell

    Thanks for the response! glad to know I'm not wasting time writing this script as a short term solution :) It's really awesome being able to talk directly to the particle system devs

    Just curious - where is the vert data stored? is it part of ParticleSystemRenderer but just not accessible?
     
  16. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    It is generated dynamically on each frame so it only ever exists temporarily (kinda like if you draw something with the GL script API).

    To expose it, we could create a script function that runs the code to generate the vert data, but pipe it into a mesh, rather than drawing it, perhaps.
     
  17. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    @richardkettlewell



    Hi Richard,

    It definitely wasn't easy, but I got something working for collision - it works for most cases. The idea is to duplicate the system as a mesh, particle by particle, and apply all the position/rotation/scaling/material/texture edits that particle system would. It currently supports
    • Any simulation mode
    • Any scaling mode
    • Nested particles
    • Texture sheet animations
    • Any particle scaling
    • Any rotation
    • Pivots
    • Mesh particles
    • 2 sided billboard particles

    The RawImage in the upper left shows the color value from the raycast (doesn't currently include ParticleSystem color modifications from StartColor or Color over Lifetime) and the hits are logged to the Console. You can add an alpha cutoff to avoid raycasting against transparent parts of particles. Raycasting is only performed if the particle system is paused (via the buttons in the custom inspector for my script).

    It's missing functionality for collision with the Trails module since i'm not sure how to get the billboarded vert data from the TrailRenderer either. 3D scaling also seems to break my pivot logic.

    It works well enough though!

    Thanks for the help,
    John
     
    richardkettlewell likes this.