Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKoehler

Posted 23 October 2012 - 09:26 AM

Your problem could be related to calling glBufferData every frame. Is there a reason you're doing this? The spawn time and original position of your particles does not ever change, and your vertex shader appears to assume that the velocity remains constant as well. If nothing else, calling the function only once when you first create the particle system should help your program in terms of efficiency.

Since you're simulating your particle's position using a single velocity value and its' point of origin. I think you'll find that particle effects will be rather boring when simulated that way. Allow me to suggest some alternative options:

Plain old CPU simulation! You can do something similar to what you're doing now (although I recommend glBufferSubData) to pass a 4 component (position.xyz, time) vector for each particle to your shader, along with uniforms for initial and final (or multiple over time) values for color and scale, and use your time value to interpolate between those in the shader. This will let you handle more complex particle physics such as acceleration while not changing your implementation too much.

If you really want to simulate particles using the vertex shader, I'd suggest using GL_ARB_TRANSFORM_FEEDBACK2 (or GL_EXT_TRANSFORM_FEEDBACK if the ARB version isn't available to you). This will allow you to write the output of a vertex shader back into a buffer, which means you can account for accelerations, changing velocity, and any other properties you may wish to update over time. Note that Transform Feedback probably won't let you write to more than one buffer at a time on GL 2, so you'd probably need to do multiple draw calls to update a system with changing velocity and position.

Another option for GL 2 is to use a pixel shader to do your particle physics, and store properties that change over time in floating-point textures. You can then use vertex texture fetch to read position, age, etc. from said textures in your vertex shader. This will require GL_ARB_texture_float, while you can look up textures in your vertex shader using texture2DLod.

#1Koehler

Posted 23 October 2012 - 09:25 AM

Your problem could be related to calling glBufferData every frame. Is there a reason you're doing this? The spawn time and original position of your particles does not ever change, and your vertex shader appears to assume that the velocity remains constant as well. If nothing else, calling the function only once when you first create the particle system should help your program in terms of efficiency.

Since you're simulating your particle's position using a single velocity value and its' point of origin. I think you'll find that particle effects will be rather boring when simulated that way.

Plain old CPU simulation! You can do something similar to what you're doing now (although I recommend glBufferSubData) to pass a 4 component (position.xyz, time) vector for each particle to your shader, along with uniforms for initial and final (or multiple over time) values for color and scale, and use your time value to interpolate between those in the shader. This will let you handle more complex particle physics such as acceleration while not changing your implementation too much.

If you really want to simulate particles using the vertex shader, I'd suggest using GL_ARB_TRANSFORM_FEEDBACK2 (or GL_EXT_TRANSFORM_FEEDBACK if the ARB version isn't available to you). This will allow you to write the output of a vertex shader back into a buffer, which means you can account for accelerations, changing velocity, and any other properties you may wish to update over time. Note that Transform Feedback probably won't let you write to more than one buffer at a time on GL 2, so you'd probably need to do multiple draw calls to update a system with changing velocity and position.

Another option for GL 2 is to use a pixel shader to do your particle physics, and store properties that change over time in floating-point textures. You can then use vertex texture fetch to read position, age, etc. from said textures in your vertex shader. This will require GL_ARB_texture_float, while you can look up textures in your vertex shader using texture2DLod.

PARTNERS