0

I've put a GPU particle system into my scene, copied from this example:

https://threejs.org/examples/?q=particle#webgl_gpu_particle_system

I've noticed that with the skybox present, the particles will never render visibly. Similarly, with the skybox removed, the particles only appear "behind" the spaceship and asteroids in the scene, when in fact some of the particles are positionally closer to the camera than the spaceship and asteroids. Screenshot

How can I have the particles appear normally in 3D space, with proper layering?

ahaas
  • 3
  • 1
  • 2
  • It appears that the particle system is one Object3D, so I can't just change the rendering order of the entire system. Some particles _should_ be behind other objects, while some particles _should_ be in front of other objects. If normal Object3Ds can have vertices both behind and in front of other objects, why can't the particle system? – ahaas Mar 11 '18 at 21:27

1 Answers1

1

There are two problems. One is that particle systems aren't neccesarily depth sorted.. so you may need to control rendering order explicitly...

three.js: how to control rendering order

The second problem is with transparent (alpha blended) objects, generally.

Read up on alpha blending, and z-buffering, depth sorting, and alpha test, specifically.

If you are just using additive blending, as that example code appears to be, then you might be fine with just the rendering order stuff described above.

The reason particle systems can't easily sort is because there are so many of them, and they are managed by the GPU, so sorting them would require pulling the data back from the GPU, to the CPU, sorting (in javascript), and then re-uploading, which would make the systems many orders of magnitude slower.

What you can do however is use z-buffering, and alphaTest, but this can cause slight alpha fringe halos around some of the particles when they happen to render in an unlucky order...

Since the particles are so small, this likely won't matter but if you start expanding the system to use larger particle sprites with different shapes, it may become an issue.

64blit
  • 5
  • 4
manthrax
  • 4,918
  • 1
  • 17
  • 16
  • Thanks for the insight. Do games like Half-Life 2 (Source Engine) use the CPU to simulate particles? For example in Half-Life 2 there are very realistic spark effects that bounce around on the world. For a system of a few hundred to a few thousand particles, is it realistic to just use CPU sprites? – ahaas Mar 13 '18 at 17:02
  • Yes. For small systems, or systems that need to interact dynamically with the environment, running them on the cpu is fine.. and really, you can actually update a fair amount on the cpu, but you'll just have to do tests to monitor what impact they have and decide if it's worth it. If you want some limited world interaction in a GPU particle system, sometimes you can do a pre-collision when you launch your system, and find the 3 nearest plane surfaces near the system, and then upload those planes to your particle system to interact with on the GPU. – manthrax Mar 17 '18 at 01:27