• Advertisement
Sign in to follow this  

Problem in my system of Particles

This topic is 2743 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

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

Thanks in Advance

Share this post

Link to post
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 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);

//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;
ZWriteEnable = false;


here's the texture I use

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

Share this post

Link to post
Share on other sites
Quote from the article:
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 this post

Link to post
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 this post

Link to post
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 this post

Link to post
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_radius
angle = random() * 2 * pi
vel.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 this post

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

  • Advertisement