Jump to content
  • Advertisement
Sign in to follow this  
Florian22222

ParticleSystem doesn´t take size&color right

This topic is 2530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
[color=#880000]//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!

Share this post


Link to post
Share on other sites
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;
};
};

Share this post


Link to post
Share on other sites
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;
};
};

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!