Jump to content

  • Log In with Google      Sign In   
  • Create Account


GPU Particle Class Design


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 benp444   Members   -  Reputation: 177

Like
0Likes
Like

Posted 05 October 2012 - 02:13 PM

I have gone through the GSParticles demo that comes with the DirectX SDK and studied Frank Lunas chapter on particles in his DirectX 10 book. I can get particles working and have no problem understanding the basics however I am struggling to come up with a good solution or class design such that I can create (e.g.) explosions whenever I want.

Here is a basic requirement that I want:

1) Create a particle explosion on the GPU using a geometry shader - similar to the GSParticle but the explosion will start and then complete. Lets say the explosion lasts for 3 seconds.
2) be able to create an arbitrary amount of explosions within in reason (e.g. 5) without disrupting the existing ones.
3) be able to create these explosions during any game frame I choose.
4) An example of the above would be explosion a) at t=0 secs, explosion b) at t=0.5, c) at t=2.5, d) at t=360 etc.

The pseudo code looks at bit like this:


[source lang="cpp"]class Particle { void init(); void render(); //this actually takes the elapsed and totalTime as well}Particle::init(){m_fXPosition= m_pEffect10->GetVariableByName( "g_position" )->AsVector();}Particle::render() {//update passm_fXPosition->SetFloatVector((float*)&m_position);if(firstTime) Draw();else DrawAuto();//render pass, passes in elapsed time//etc...}[/source]

This class currently works in my game as it stands e.g:

[source lang="cpp"]onDeviceInit() {m_explosion=new Particle();m_explosion.init();}onFrameUpdate() {//an explosion event occurred som_explosion.reset(); //sets first time to true;}onFrameRender() {//this is continually called whether there are particles alive or not.m_explosion.render();}[/source]

The above however fails requirement 2. If a second explostion event occurs before the existing one is complete then the existing particles will be destroyed because firstTime will be true and Draw() will be called.

My shader is very similar to GSParticles.fx and for the sake of this topic consider it the same.

I appreciate that seeding particles might be the way to go and of course GSParticle has a single seed (PT_LAUNCHER), but I can't see how I can inject seeds to an already running shader.

Bearing in mind that I don't want to create a new Particle class and call init() everytime I want an explosion, The only way I can see of doing this would be to create (e.g.) 5 particle instances and store them in an array. Then when I want an explosion I get the next instance set its position. This would allow me a maximum of 5 explosions at any given time (a 6th explosion would kill all particles in the 1st explosion).

Can anyone give me some hint as to how to create a simple particle framework using Geometry shaders in DirectX 10?

Edited by benp444, 05 October 2012 - 02:18 PM.


Sponsor:

#2 benp444   Members   -  Reputation: 177

Like
0Likes
Like

Posted 05 October 2012 - 05:38 PM

Sorry, solved it. I have created a shader variable (g_createExplosion). On each frame if this is set to true it will kick off another cycle of particles without effecting the existing ones.

#3 ATEFred   Members   -  Reputation: 1055

Like
0Likes
Like

Posted 05 October 2012 - 06:27 PM

Not what you asked, but I would recommend looking into using append / consume buffers to add to and update your particle buffers on compute shaders, and draw indirect to render them. Alot more straightforwards than using the GS, and I suspect better performance for large particle counts (500k-1m).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS