• Advertisement

Archived

This topic is now archived and is closed to further replies.

Point sprites with glow and alpha blend

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

How could I combine the effect that comes from Blend.One - Blend.One and Blend.SourceAlpha - Blend.InvSourceAlpha? With first one you get nicely glowing particle effects, but no fading (expect color fading into background). The second one gives nice blending into surroundings, but makes ugly black boxes around the particles. I would like to have the glow, fade, but no black boxes. What should I do? Business is business and Moses is Moses [Homesite]
Advertisement
A forum search on point sprites would find a lot of good information. Like this post:
http://www.gamedev.net/community/forums/topic.asp?topic_id=218343


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
Yeah, I searched around, but could find the answer. That thread didn''t help me much. I could show some pictures:

This is with blend one, and the fading is done with color:
One

This is with alpha blend, so no color trick are needed, and the particles fade nicely, but with black boxes and without the nice blend one effect:
Alpha

I would like to combine them both, and get rid of the black boxes...

Business is business and Moses is Moses
[Homesite]
Guest Anonymous Poster
There''s a technique called "SoftAdd" which is basically

srcblend = invdstcolor
dstblend = one

Share this post


Link to post
Share on other sites
When you say "Blend.SourceAlpha - Blend.InvSourceAlpha" are you implying you set the blendmode to subtract?

A standard alpha blend is
SrcBlend = D3DBLEND_SRCALPHA
DestBlend = D3DBLEND_INVSRCALPHA
BlendOp = D3DBLENDOP_ADD
DX9''s new AlphaSrcBlend and AlphaDestBlend can be ignored.

This is the standard normal alpha blend. This should not produce any black boxes. When alpha is 0, you get destcolor, when alpha is 255 you get srccolor.

Share this post


Link to post
Share on other sites
Looking at your image, it looks like your alpha is coming from your vertices, and not from your texture.

What you want is both to have an effect. Set alpha blending in your texture stage states to the following:
alphop = modulate
alphaarg1 = diffuse
alphaarg2 = texture

Share this post


Link to post
Share on other sites
Hmm, I''m still put of luck. This is what I do now:


// I set the particle''s color so that the color itself doesn''t change, but the alpha decreases as the lifetime goes down

p.Color = Color.FromArgb((int)((p.Lifetime / p.OriginalLifetime) * 255.0f), p.Color);

// Here''s the stages I''ve been setting

device.RenderState.PointSpriteEnable = true;
device.RenderState.PointScaleEnable = true;
device.RenderState.AlphaBlendEnable = true;
device.RenderState.ZBufferEnable = false;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.RenderState.BlendOperation = BlendOperation.Add;
device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
device.TextureState[0].AlphaArgument0 = TextureArgument.Diffuse;
device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
device.RenderState.PointSize = 0.05f;
device.SetTexture(0, texture);


These give me this

Business is business and Moses is Moses
[Homesite]
Your code looks just fine, but it seems like your texture either doesn''t have an alpha channel or it''s filled with one value. The alpha channel should look similar to one of your RGB channels (opaque at the center, fading out towards the edges). If you want alpha-blended particles to be as bright as the additive ones, the RGB part of the texture should be a solid bright color (or switch to pre-multiplied alpha).

Share this post


Link to post
Share on other sites
Your image doesn''t have alpha in it. If you want to blend based on per-pixel alpha rather than color, you''re going to have to use an image that contains per-pixel alpha values.

Use the DXTextureTool that comes with the SDK to take two images, your color image, and an alpha image, and merge them into a single image with color and alpha. (preferably you''d do all this in Photoshop, but I''m assuming you don''t have that, being expensive and all).

Share this post


Link to post
Share on other sites
Yes, I don't have Photoshop, but I have PSP lying around. I'll see what can I do with it. Even if I get rid of the black boxes by creating the particle texture on transparent background, how can I get the glow effect working? Like this?

I mean how could I have the alpha blending and the glow effect from blend one-blend one working at the same time?

Business is business and Moses is Moses
[Homesite]

[edited by - Miksan on April 12, 2004 4:34:49 PM]
You can get that by using destblend of one, but otherwise using the same values as above.

This works out as (srcalpha * srcpixel) + (destpixel * 1). So, the new image will blend out with your particle alpha multiplied by the texture alpha. This will then be added to the current back buffer value.

Doing this, you could pre-multiply your bitmap, and not have alpha in it, since you don''t need per pixel alpha for anything other than scaling the srcpixel values. Just fade your image to black at the edges. The the vertex alpha will scale the bitmap''s brightness before adding it to the back buffer.

Share this post


Link to post
Share on other sites
Great, it works now. Here''s the code:


device.RenderState.ZBufferEnable = false;
device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.One;
device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
device.RenderState.PointSpriteEnable = true;
device.RenderState.PointScaleEnable = true;
device.RenderState.PointSize = 0.05f;
device.SetTexture(0, texture);


Here''s a screenie also (console is also visible ): Clicky

Business is business and Moses is Moses
[Homesite]
Simple black particles would be a black sphere with fading alpha on the outside and normal alpha blending (srcblend=srcalpha, destblend=invsrcalpha).

Share this post


Link to post
Share on other sites

  • Advertisement