Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Galaxy simulator in unity webgl possible?

Discussion in 'Web' started by dansav, Oct 11, 2023.

  1. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    I want to duplicate this galaxy simulator in unity webgl.

    Here's the three.js webgl project
    https://github.com/andrewdcampbell/galaxy-sim

    It currently is built in three.js and uses about 28000 particles if I'm reading the init.js file correctly. As a start I was thinking I would just instantiate 20,000 quads with a billboard shader and gpu instancing and control their positions with an equation, but so far my experiments struggle with 1000 particles. Why is three.js able to handle this and unity webgl not able to handle it?

    Also I've seen some webgl demos with 100,000 particles. Unity seems to choke even in the editor if I use their built in particle system with 50K particles gpuinstancing etc, the frame rate drops to a few per second on a 2019 macbook pro.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,979
    You are testing this with URP? If not, do so. Built-in renderer is a massive churn for webgl.
    You should also look into GPU instancing. Not sure if WebGL supports this though.

    The demo might be using a shader to render the particles. It may also be using multithreaded code to speed up the gravity calculations. However Unity currently only supports native (C++) multithreading for WebGL.

    It also appears to use render scale until you hit 'L'.