Search Unity

Looking for some advice on using a compute shader to control particle postions

Discussion in 'Shaders' started by joshszman09, Mar 21, 2018.

  1. joshszman09

    joshszman09

    Joined:
    Mar 12, 2017
    Posts:
    8
    So I am working on a galaxy simulation just for fun and I have run into some CPU limitations. For the simulation, I create the stars using a particle system and update the positions in Update(). This works well up to about 50,000 particles, but after that I get some serious slow down. I'd like to move the position calculations to the GPU using a compute shader to speed things up and increase the max particles but I've never made a custom shader before.

    I was hoping someone on this forum could point me towards some resources on how to do something like this. I started reading the manual but honestly got a little lost. Does anyone know of any tutorials out there that deal specifically with using a compute shader to update particles? Any advice would be really helpful.
     
  2. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
    Simple example - animated 20 milions particles (total 120 lines of code ):



    See two source codes in video description. Apply CS script to Main Camera, and set material with shader.
     
    Jelmer123 likes this.