4
\$\begingroup\$

I have been implementing a simple GPU-based particle system in Unity, for my current game. The setup is indeed not very elaborated: the shader receives a set of coordinates passed trough the position of the vectors of a mesh, then generates a quad on the fly (via geometry shader). And then, it applies the mesh texture as the texture to the generated quad.

Performance, by doing this, has showed an incredible boost in my game in comparison to using Unity's built-in system. Therefore, I am trying to extend it a bit further and implement now a couple of functionalities: a) particles' lifetime; b) particles that "blink", i.e. that are not displayed for a few microseconds.

In order to achieved both tasks, I imagine that I need a way to store information for each particle from one frame to the next. However, this certainly cannot be done at the mesh level due to performance concerns: downloading or uploading information from the mesh is very expensive. Besides computational shaders (which are currently out of consideration), the only way I read about is using a texture to store the information.

Then, in general terms, my question is how to do that? Being more specific, I can't quite understand how a texture could store, for instance, the position or the lifetime of each particle. Sure, each pixel of the texture has a RGBA information, but that is just it. Besides,in Unity, RGBA is set from 0 to 1 and, worse, RenderTexture does not have a SetPixel function. Therefore:

1) how can each pixel store position and lifetime of each particle? 2) how can each particle known which is its respective pixel and loard/save from/to it?

If anyone could show me a couple of lines of shader pseudo-code, that would be amazing and ideal. But conceptual explanations are very much welcome too.

\$\endgroup\$
1
  • \$\begingroup\$ My gut instinct is to use something like MVC for this, where the particle emitter is the controller, and it stores information about the models (the particles), which are the view. I'm not sure if this would work in Unity, though; if the only way to have persistent data is to save it to a texture, rather than having a list or map field, it would be a pain to implement. \$\endgroup\$
    – anon
    May 11, 2016 at 11:03

0

You must log in to answer this question.

Browse other questions tagged .