0

I'm building a particle sim using OpenGL and am trying to benchmark the various methods of setting up the particles. Before I progress to instancing or transform feedback, I wanted to create independently moving points using only a standard VBO.

So far I have tried moving points by updating the buffer data using glBufferSubData, filling up an empty buffer. However, the frame rate drops as soon as you get close to 10,000 points. I need at least a few million for my purpose eventually.

At this minute I'm now experimenting with transformation matrices and have the following:

In my shader:

in layout(location = 0) vec3 positions;

uniform mat4 transform[10];

void main(){

    int count = 0;   
    count + 1;
    gl_Position = transform[count] * vec4(positions, 1.0);

}

and in my program draw loop:

self.matrices[i] = Matrix44.from_translation(Vector3([0.0,-self.t,0.0]))

glUniformMatrix4fv(self.transformMatrixNameloc,10,GL_FALSE,self.matrices[i])

Although this seems to be working, I cannot get the time (self.t) to reset / restart each time for each new particle drawn. I'm using this variable for testing by the way, in place of a gravity force for now.

Any ideas?

Many thanks,

Nas25
  • 55
  • 6
  • Hard to tell from the code you are showing us what exactly is the issue with `self.t`. As a side note, getting 1 million particles to render at an interactive frame rate is not exactly trivial. See [this](http://voidptr.io/blog/2016/04/28/ldEngine-Part-1.html) for some information on what steps you might need to take to reach that goal. – CodeSurgeon Apr 11 '18 at 04:37
  • Thank you for the link, codesurgeon. I'd like to see how 'better' the performance is on my target machine (for documentation purposes really). Therefore I'd like to know if I can do this using matrices then and test 1M+ particles before I do actually implement an instancing or TF system. At the moment I can get different matrices set up etc, but the 'self.t' time variable starts and increments from 0 at run-time mimics real-time in seconds. By the time the next matrix is sent the time has progressed. Am I missing something silly here? :/ – Nas25 Apr 11 '18 at 11:13
  • Some more reading. I would only get the time once at the start of every frame and use that same time for all of the particles you are drawing. I would read up [this famous article](https://gafferongames.com/post/fix_your_timestep/) as well as [this one](http://gameprogrammingpatterns.com/game-loop.html). This should show how you should move your particle simulation in a deterministic lockstep. – CodeSurgeon Apr 11 '18 at 15:21
  • Also, from your `uniform mat transform[10];` statement in your vertex shader, it looks like you are only passing matrices for 10 particles? If that means you are calling `glDrawArrays` in groups of 10 particles, you should not do that, but instead try to batch as many particles at once as is possible. – CodeSurgeon Apr 11 '18 at 15:23
  • Your question is quite interesting, one advice though, in order to get really interesting answers I'd suggest you post a [mcve](https://stackoverflow.com/help/mcve) of what you've attempted so far – BPL May 08 '18 at 21:43

0 Answers0