0

I'm trying to implement a state preserving particle system on the iPhone using OpenGL ES 2.0. By state-preserving, I mean that each particle is integrated forward in time, having a unique velocity and position vector that changes with time and can not be calculated from the initial conditions at every rendering call.

Here's one possible way I can think of.

  1. Setup particle initial conditions in VBO.
  2. Integrate particles in vertex shader, write result to texture in fragment shader. (1st rendering call)
  3. Copy data from texture to VBO.
  4. Render particles from data in VBO. (2nd rendering call)
  5. Repeat 2.-4.

The only thing I don't know how to do efficiently is step 3. Do I have to go through the CPU? I wonder if is possible to do this entirely on the GPU with OpenGL ES 2.0. Any hints are greatly appreciated!

hanno
  • 6,401
  • 8
  • 48
  • 80
  • What data is stored in step 2 and what type of data are you expecting to transfer in step 3? – Kimi Jun 13 '13 at 15:59
  • For simplicity, lets say 4 floating point numbers per vertex. I would write them to the rgba values of the texture in the fragment shader (one pixel per particle/vertex/fragment). – hanno Jun 13 '13 at 16:03

1 Answers1

2

I don't think this is possible without simply using glReadPixels -- ES2 doesn't have the same flexible buffer management that OpenGL has to allow you to copy buffer contents using the GPU (where, for example, you could copy data between the texture and vbo, or use simply use transform feedback which is basically designed to do exactly what you want).

I think your only option if you need to use the GPU is to use glReadPixels to copy the framebuffer contents back out after rendering. You probably also want to check and use EXT_color_buffer_float or related if available to make sure you have high precision values (RGBA8 is probably not going to be sufficient for your particles). If you're intermixing this with normal rendering, you probably want to build in a bunch of buffering (wait a frame or two) so you don't stall the CPU waiting for the GPU (this would be especially bad on PowerVR since it buffers a whole frame before rendering).

ES3.0 will have support for transform feedback, which doesn't help but hopefully gives you some hope for the future.

Also, if you are running on an ARM cpu, it seems like it'd be faster to use NEON to quickly update all your particles. It can be quite fast and will skip all the overhead you'll incur from the CPU+GPU method.