Jump to content

  • Log In with Google      Sign In   
  • Create Account


ParticleSystem doesn´t take size&color right


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

#1 IceBreaker23   Members   -  Reputation: 539

Like
0Likes
Like

Posted 14 January 2012 - 05:30 PM

Hi!

I am currently building a simple particle system with directx 9.
The problem is that the vertex shader only takes the position right, but not the size or color.

My struct for particle:
class Particle
{
public:
D3DXVECTOR3 position;
D3DXVECTOR3 velocity;
float timeLeft;
float size;
D3DXCOLOR color;
//no need for FVF because of effect file
static DWORD GetFVF()
{
  return (0);
};
};

My vertex shader:
uniform extern float4x4 gWVP;
struct OutputVS
{
float4 pos : POSITION0;
float4 color : COLOR0;
float2 tex0 : TEXCOORD0;
float size : PSIZE;
};
OutputVS ParticleVS(float3 pos : POSITION0,float3 vel : TEXCOORD0, float timeLeft : TEXCOORD1,float size : TEXCOORD2,float4 color : COLOR0)
{
OutputVS outVS = (OutputVS)0;

outVS.pos = mul(float4(pos,1.0f),gWVP);
outVS.size = size;
outVS.color = color;

return outVS;
}
technique ParticleSystem
{
pass P0
{
  vertexShader = compile vs_3_0 ParticleVS();

  PointSpriteEnable = true;
}
}

The particles do not have a fixed color. They have(so it seems) random colors and the size is always 1.
If I change
outVS.size = size;
to:
outVS.size = 5.0f;
they become bigger.

Sponsor:

#2 kauna   Crossbones+   -  Reputation: 1899

Like
1Likes
Like

Posted 14 January 2012 - 06:32 PM

//no need for FVF because of effect file

Hi,

I hope you are setting the vertex declaration instead. The vertex declaration needs to match the vertex shader side vertex input structure.


Cheers!

#3 IceBreaker23   Members   -  Reputation: 539

Like
0Likes
Like

Posted 15 January 2012 - 04:51 AM

Thanks, I think i skipped this site in my book.

Cheers!

#4 IceBreaker23   Members   -  Reputation: 539

Like
0Likes
Like

Posted 15 January 2012 - 05:28 AM

I´ve now updated my particle class.
But i get an error on creating the vertex declaration!

struct Particle
{
D3DXVECTOR3 position;
D3DXVECTOR3 velocity;
float timeLeft;
float size;
D3DXCOLOR color;
//no need for FVF because of effect file
static DWORD GetFVF()
{
  return (D3DFVF_XYZ | D3DFVF_TEX0 | D3DFVF_TEX1 | D3DFVF_TEX2 | D3DFVF_DIFFUSE);
};
//for effect file
static D3DVERTEXELEMENT9 *GetDecl()
{
  static D3DVERTEXELEMENT9 decl[] =
  {
   {0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,0},
   {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,0},
   {0, 24, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,0},
   {0, 28, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,0},
   {0, 32, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,0},
   D3DDECL_END()
  };
  return decl;
};
};


#5 IceBreaker23   Members   -  Reputation: 539

Like
0Likes
Like

Posted 15 January 2012 - 06:06 AM

solved by using this:

struct Particle
{
D3DXVECTOR3 position;
D3DXVECTOR3 velocity;
float timeLeft;
float size;
D3DCOLOR color;
//no need for FVF because of effect file
static DWORD GetFVF()
{
  return (D3DFVF_XYZ | D3DFVF_TEX0 | D3DFVF_TEX1 | D3DFVF_TEX2 | D3DFVF_DIFFUSE);
};
//for effect file
static D3DVERTEXELEMENT9 *GetDecl()
{
  static D3DVERTEXELEMENT9 decl[] =
  {
   {0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,0},
   {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,0},
   {0, 24, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,1},
   {0, 28, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,2},
   {0, 32, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,0},
   D3DDECL_END()
  };
  return decl;
};
};





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