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.

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]
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 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...

[Homesite]
There''s a technique called "SoftAdd" which is basically

srcblend = invdstcolor
dstblend = one

Share on other sites
Sorry AP, but I can''t see how the alpha would be taken in to account in that situation?

[Homesite]
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
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 on other sites

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 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 downp.Color = Color.FromArgb((int)((p.Lifetime / p.OriginalLifetime) * 255.0f), p.Color);// Here''s the stages I''ve been settingdevice.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

[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 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 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?

[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 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

[Homesite]
I''ll continue this thread, I think new one is not necessary...

How could I make black particles show up? Like doing thick black smoke or something? If I color my particle black, it becomes transparent. If I blend them, they get brighter...?

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