Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Where is my particle?


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
No replies to this topic

#1 swdever   Members   -  Reputation: 176

Like
0Likes
Like

Posted 18 May 2013 - 04:25 AM

   Hey,

   I am studying the sample ParticlesGS in the DX SDK. I try to implement a simpler fireworks myself. But there's some thing wrong in my Stream Out Geometry Shader. Here's my GS code.

[maxvertexcount(100)]
void StreamOutGS( point Particle input[1], inout PointStream<Particle> pStream )
{
	input[0].age += gTimeStep;
	if( input[0].type == PT_EMITTER )
		GSEmitterHandler( input[0], pStream );
	else if( input[0].type == PT_SHELL )
		GSShellHandler( input[0], pStream );
	else if( input[0].type == PT_EMBER1 )
		GSEmber1Handler( input[0], pStream );
}

 

  The struction and functions used in the StreamOutGS are defined before,like these:

struct Particle
{
	float3 pos : POSITION;
	float3 vel : VELOCITY;
	float2 size : SIZE;
	float age : AGE;
	uint type : TYPE;
};

   

cbuffer cbFixed
{
	float gSecondPerShell = 1.0;
	float gShellLife = 3.0;
	float gEmber1Life = 2.0;

	float3 gAcceW = { 0.0f, -9.8f, 0.0f };
};


#define PT_EMITTER 0//particle type
#define PT_SHELL   1
#define PT_EMBER1  2

void GSGenericHandler( Particle input, inout PointStream<Particle> pStream )
{
	input.pos += input.vel * gTimeStep + 0.5 * gTimeStep * gTimeStep * gAcceW;
	input.vel += gTimeStep * gAcceW;
	pStream.Append( input );
}

void GSEmitterHandler( Particle input, inout PointStream<Particle> pStream )
{
	if( input.age > gSecondPerShell )
	{
		float3 vRandom = RandUnitVec( PT_SHELL );//return a random unit vector,defined before
		Particle p;
		p.pos = input.pos;
		p.vel = input.vel + 8.0f * vRandom;
		p.size = float2( 1.0f, 1.0f );
		p.age = 0.0f;
		p.type = PT_SHELL;
		
		input.age = 0.0f;
		pStream.Append( p );
	}
	pStream.Append( input );
}

void GSShellHandler( Particle input, inout PointStream<Particle> pStream )
{
	if( input.age >= gShellLife )
	{
		Particle p;
		float3 vRandom = float3( 0.0f, 0.0f, 0.0f );

		for( int i = 0; i < 30; ++i )
		{
			vRandom = RandUnitVec( PT_EMBER1 + i );////return a random unit vector
			p.pos = input.pos;
			p.vel = input.vel + 15.0 * vRandom;
			p.size = float2( 0.8f, 0.8f );
			p.age = 0.0f;
			p.type = PT_EMBER1;

			pStream.Append( p );
		}
	}
	else
		GSGenericHandler( input, pStream );
}

void GSEmber1Handler( Particle input, inout PointStream<Particle> pStream )
{
	if( input.age < gEmber1Life )
		GSGenericHandler( input, pStream );
} 

 

It seems that the emitter works well. But the shell just explodes into one ember,not thirty as I defined,that is,maybe the loop in GSShellHandler  just loops one time for each shell,I guess.Can anybody tell me where the bug is?

 

   In addition, I use the visual stdio 2012.I debug my HLSL code with its Graphics Diagnostic Tools. Each time I capture one frame,I only can access one input for debug. For example,if there are ten particles pass through my StreamOutGS,one emitter,two shells and seven embers.When I capture one frame and debug StreamOutGS,mostly,the input particle is a ember.I have no idea how to access and use the other nine particles to debug. Also,I don't know how to access a shell to debug at the exactly time it explodes. That's why I don't know how to debug my loop in GSShellHandler. Hope somebody give some help. 



Sponsor:



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