# Problem in my system of Particles

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

## Recommended Posts

I'm a bit new in game programming, I read the book Introduction to Direct X9.0c A shader Approach, then I tried to make the mist effect as a try before going for the explosion http://www.gamedev.net/reference/articles/article2701.asp.
But It doesn't seem to work as NOTHING IS BEING DRAWN ON THE SCREEN and I don't know what is going wrong.I uploaded my code any help will be greatly appreciated.

the link of my code : http://www.4shared.com/file/97EeA3oX/MistEffect.html

##### Share on other sites
Ok I solved my Code Problem but the system looks bad :/
here's a video of it

and here's my effect Code
float4x4 Projection;float4x4 World;float4x4 View;int ViewportHeight;texture gTexture;float3 EyePos;float3 acceleration;float globalTime;sampler TexS = sampler_state{	Texture = <gTexture>;	MinFilter = Linear;    MagFilter = Linear;    MipFilter = POINT;    AddressU = CLAMP;    AddressV = CLAMP;};struct VS_OUTPUT{	float4 posH : POSITION0;	float4 color : COLOR0;	float2 tex0 :TEXCOORD0;	float size : PSIZE;};struct VS_INPUT{	float3 posL : POSITION0;	float3 vel : TEXCOORD0;	float size : TEXCOORD1;	float time : TEXCOORD2;	float lifeTime : TEXCOORD3;	float mass : TEXCOORD4;	float4 color : COLOR0;};VS_OUTPUT MistVS(VS_INPUT input){	VS_OUTPUT output = (VS_OUTPUT) 0;		float t = globalTime - input.time;		float sine,cosine;	sincos(0.5f *input.mass*t,sine,cosine);		float x = input.posL.x*cosine + input.posL.y-sine;	float y = input.posL.x*sine + input.posL.y-cosine;		float s = sin(2.0f*t);	input.posL.x = x;	input.posL.y = y+input.mass*s;		//New Position Integration	input.posL = input.posL + input.vel*t+0.5f*acceleration * t*t;		float4 worldposition  = mul(input.posL,World);	float4 viewposition  = mul(worldposition,View);	output.posH  = mul(viewposition,Projection);	//input.size+=0.4f*t*t;		//Scaling with distance	float d = distance(input.posL,EyePos);	output.size = ViewportHeight*input.size/(1.0f+8.0f*d);		output.color = (1.0- (t/input.lifeTime));		return output;}float4 MistPS(float4 color:COLOR0,			  float2 tex0:TEXCOORD0):COLOR0{	return color*tex2D(TexS,tex0);}technique Mist{	Pass P0	{		vertexShader = compile vs_2_0 MistVS();		pixelShader  = compile ps_2_0 MistPS();		AlphaBlendEnable = true;		PointSpriteEnable = true;		SrcBlend = SRCALPHA;		DestBlend = INVSRCALPHA;		ZWriteEnable = false;			}}

here's the texture I use
http://img822.imageshack.us/img822/9581/mist.jpg

I guess the problem lies in my blending equation ( that's only a guess),Any ideas guys?

##### Share on other sites
Ok Does anyone know the right blending equation for making that mist effect???!
http://www.gamedev.net/reference/articles/article2701.asp

##### Share on other sites
Quote from the article:
Quote:
 The transparency is added to the mist texture in Adobe Photoshop using the image's Alpha Channel
You're using a JPEG. JPEGs don't provide an alpha channel. Use PNG instead. In that case the blending is probably meant to be additive, so source and destination are both ONE and BlendOp ADD.

Another variant is to use different blend states, probably SRCCOLOR for source and INVSRCCOLOR for destination.

But since you are using shaders, you could also stick with the JPEG and the blend states and set the alpha yourself, e.g.
return float4(color.rgb, tex2D(TexS,tex0).r * color.a);
Can't say if that works, obviously the vertex shader does some sort of fade-out to the color. Just experiment with it, then.

##### Share on other sites
Thanks for your reply I firstly thought it will be just additive blending but I didn't know about the JPEG not having an alpha channel,I tried your equation and it is better than what I did. But I guess it will be easier If anyone provides a mist texture that has an alpha channel,If anyone has it as I know nothing about Photoshop really.
Thanks again

##### Share on other sites
No need to use Photoshop. I use Paint.NET. To change an image's alpha channel you can use the DirectX SDK's DXTex tool and it's "Open onto alpha channel" feature. See the docs for details.

##### Share on other sites
Ok installing PAINT.NET and I'll see how to make that alpha channel,Hope it will be easy :), Thanks for your help

##### Share on other sites
Thnx for the help I made my system and here's a video of it any comments will be appreciated

##### Share on other sites
Looks fine, seems you even got z-order working. But how do you generate the random velocities ? Looks like you choose uniformly from a square/rectangle. I'd rather take it from a circle, e.g. choose a random magnitude and a random angle and use polar coordinates (pseudo-code):
r = random() * max_radiusangle = random() * 2 * pivel.x = r * cos(angle)vel.y = r * sin(angle)
Note: This will give an uneven distribution (velocities are more common around the center) but it might be what you are looking for.

##### Share on other sites
Thanks for your comment, and Yes the Circular generation is more nice than what I made.

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633003
• Total Posts
3009842
• ### Who's Online (See full list)

There are no registered users currently online

×