Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

best way to render a galaxy-ful of particles?

Discussion in 'General Graphics' started by JoeStrout, Jul 5, 2021.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    I'd like to do a galaxy simulation containing thousands (or better yet, millions) of stars swirling around as stars do. This is going to run on Quest (2), so maintaining a high frame rate on rather low-end hardware is a hard requirement.

    I think of it as a particle system — each star is a little billboard — but each will be orbiting the center on a different path and at different speeds. Occasionally stars will change color (indicating their status in the game). What would be the most efficient way to do this?

    • A single mesh (or, several big meshes), where I dynamically update the vertex positions (and sometimes color) every frame?
    • A particle system which I somehow get low-level control of?
    • DrawMeshInstanced?
    • uh... running out of ideas here... something related to the new Jobs system?
    • something else?
    Thanks for any suggestions... I've never faced a problem quite like this in Unity before.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    Assuming they are always present and you wont be adding/removing stars over time then you could use the Particlesystem to render the stars and store the index of each star in a script which can then do the updating when required, maybe even use DOTS for the simulation of the stars. Then when you need to update the visuals just get and set them using the index into a ParticleSystem.
    It will also help to batch them into systems by the general area so you can cull the ones not visible.

    https://docs.unity3d.com/ScriptReference/ParticleSystem.GetParticles.html
    https://docs.unity3d.com/ScriptReference/ParticleSystem.SetParticles.html
    https://docs.unity3d.com/ScriptRefe...bs.IJobParticleSystemParallelFor.Execute.html
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    All stars will be always present (or so we can assume). But every star (particle) will be moving on every frame; I'd have thought calling SetParticles each frame would be a bit heavy.

    But I'll give it a try!
     
    karl_jones likes this.
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    You can assign velocities to them. So maybe just set that and update them every so often, let the particles system move them.
     
  5. RyanKeable

    RyanKeable

    Joined:
    Oct 16, 2013
    Posts:
    62
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    Well, millions was always aspirational. I'm doing 100k stars now, and that may be sufficiently dense for my needs.
     
  7. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,357
    Maybe you can render the far-away stars to a render texture so you don't have to render them every frame.
     
    karl_jones and bgolus like this.
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
  9. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,068
    Why not group a few stars, like 2 stars on a single billboard? Some could be one star, some could be two stars, and other billboards could have three or four stars or more, on a single billboard. And then you can make them swirl around like a galaxy does.
     
    Last edited: Jul 28, 2021
    richardkettlewell likes this.
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
    You can, and that helps with vertex count, but you have to be very mindful of overdraw in the Quest. A single full screen transparent surface can be enough by itself for the frame time to get uncomfortably high (depending on the complexity of the rest of the scene). Two or three overlapping transparent surfaces and you’re going to be missing your frame time targets.
     
    richardkettlewell likes this.