Search Unity

What’s so taxing about the Noise variable in particle system?

Discussion in 'General Graphics' started by LeftyTwoGuns, Jul 4, 2020.

  1. LeftyTwoGuns

    LeftyTwoGuns

    Joined:
    Jan 3, 2013
    Posts:
    260
    I made a fantastic looking smoke trail particle that emits over distance from a projectile using the Noise variable. But shooting many of them continuously tanks the FPS. Even trying to restrain myself it still makes a noticeable impact (that is otherwise not there). I’d hate to give the effect up, so what are the proper ways to maximize efficiency with particle Noise?
     
    Last edited: Jul 4, 2020
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    In short, the noise module uses a *lot* of maths.

    There are 2 main things you can do to make it cheaper, aside from the obvious (fewer particles) ;-)

    1. Reduce the Octaves. This is the number of times the noise algorithm runs. Each octave is a layer of noise. If you can make your effect look as good with fewer octaves, you will reduce the time it takes significantly.

    2. Use lower quality settings. This also reduces the amount of times the noise maths is executed, but can also make the movement look more repetitive.

    Hope it helps!
     
  3. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    you can split your particle systems too, this can help with variability but also compartmentalizes : a minimalist approach

    i.e. only need 1/x of the visual to have 'heavy' noise and 1/2 of the effect using the cheaper noise

    • heavy noise (1/8 billboards)
    • medium noise (2/8 billboards)
    • light noise (3/8 billboards)
    • no noise (2/8 billboards
    etc..

    allows teams to parameterize/LOD adjust bottlenecks at runtime per device by tuning the systems
    independently

    also @richardkettlewell what noise function is it?
    would this be an area where different functions helps?
    my understandings are pedestrian but afaik I am to use Perlin noise in shaders as this is the cheapest for low counts, but simplex for higher complexities
     
    Last edited: Jul 5, 2020
    richardkettlewell likes this.
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    It’s Curl Noise, which is implemented as a “few” Perlin Noise passes. The exact number depends on the quality and octave count.

    It can be done with cheaper “value” noise, in exchange for a compromise of visual quality, but I think I opted to only use Perlin. (I’d have to check the code to remind myself 100% though)

    EDIT: I checked - we always use Perlin.
     
    Last edited: Jul 6, 2020
    Torbach78 likes this.
  5. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    yes i think this is an area where artists don't have experience, - the complexity of the solution is ^2 (analogous to texture size)
    dimension (3d) * billboard count

    perlin (3d)
    2^n
    = 2*2*2
    = 8

    simplex (3d)
    n^2
    = 3*3
    = 9

    is my understanding of this accurate?
    simplex only helps >3d which artist don't use in shuriken.

    but the idea of it growing 2,4,8 is important

    how does the octaves : dimensions relate?
    is it simply +X octave(s) = *X of the work?
     
    Last edited: Jul 6, 2020
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Ok, to be precise about the numbers:

    Quality Low/Medium/High chooses whether to use 1D, 2D or 3D Perlin noise. Each level involves more maths than the previous, but I wouldn't like to try and be more precise about how much more, without really studying it.

    To get 1 final noise sample, we call the noise function once per octave.
    Then, to get a Curl Noise sample, we repeat the process 3 times, with different inputs. (These results get combined later to get a final "direction of movement" value)

    So, for example, for High Quality noise, with 2 octaves, that would be:
    (3D Perlin) * 2 * 3 = 6 passes of 3D Perlin Noise.

    And for Low Quality noise with 4 octaves:
    (1D Perlin) * 4 * 3 = 12 passes of 1D Perlin Noise.

    Hope that helps :)
     
  7. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    1D Perlin noise needs to evaluate values at two closest grid points, apply a polynomial to the fractional part of the input coordinate and do a single linear interpolation.
    3D Perlin noise needs to do the same on a cube = evaluate 8 closest grid points, apply a polynomial 3 times (x,y and z) and do 7 lerps (4 on X, 2 on Y and one on Z dimensions).

    N-dimensional Perlin noise does 2^N grid value evaluations, computes N polynomials and does 2^N-1 linear interpolations. Per pass :)
     
    richardkettlewell likes this.
  8. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    at this point evaluation has gone over my head but I need a ballpark to communicate with other artists

    could the comparison be
    1D : 2 * oct * 1lerp == 2
    2D : 4 * oct * 3lerp == 12
    3D : 8 * oct * 7lerp == 56

    i.e. [1:6:28]
    2D noise is x6 the cost of 1D
    3D noise is x28 the cost of 1D

    or...
    1D = 2points * 1polynomial *1lerp
    2D = 4points * 2polynomial *3lerp
    3D = 8points * 3polynomial *7lerp

    [1:12:84]

    if 1D was 1.1% the math cost of 3D this is something i'd want other vfx artists in mobile to be aware of
     
  9. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    If you need numbers for artist budgets then I think the best way will be to make some example systems with eg 10K particles in each, with various settings (1 system per test scene) and look at the timeline profiler on your target platform to see how long the update job takes in milliseconds for each.

    The cost will more-or-less scale linearly with particle count, so you can then start to say things like "if using high quality, 1000 particles will cost you 1ms of update job time". and "if using 2 octaves on that same system, you're up to 2ms".

    The main gotcha is, that the particle update is multi-threaded, so if you have 4 worker threads, then simulating 1 particle effect costs the same as 4 (slight over-simplification!).

    We also have this, which gives some indication of module costs relative to one-another, but it's very high level, and only uses one (unknown) config for the Noise Module:


    Another option is to write a script that called ParticleSystem.Simulate, wrapped with some timing info. Then you could change a setting, re-run, and quickly get an idea of the relative difference each quality/octave count made to a system.
     
    Last edited: Jul 8, 2020
  10. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    PS. Evaluating the polynomials is more expensive than the lerps.