• Create Account

## Blending the edges of a explosion

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

11 replies to this topic

### #1jdean300  Members

255
Like
0Likes
Like

Posted 16 February 2014 - 02:22 PM

I am working on adding in explosions to a space-themed shoot-em-up game I've been working on. I have generated the explosion animations using a free explosion generator, but have run into an issue. The smokey grey edges around all my explosion images stand out way to much because they are not transparent at all, as smoke should be. The only solution I have discovered so far is to manually edit out all the light colored pixels around the edges of the explosion, as seen on the left image in the attachment.

This is a great deal of work to have to do for every animation frame, and since I plan on adding different explosions, this is quickly going to become ridiculous. Also, its taking away from the visual quality of the explosion. So, is there a way to blend the smokey edges around the explosions with the background? My understanding is its not as simple as just setting the alpha mode for the image, because that would blend the center of the explosion as well.

Hopefully I've explained my issue well enough. Thank you in advance for any suggestions.

### #2warnexus  Prime Members

1535
Like
1Likes
Like

Posted 16 February 2014 - 04:18 PM

Try GIMP. It is an image editor that can apply transparency to images pretty well.

1) Select Layer > Transparency > Add Alpha Channel.

2) Tools > Selection Tools > Fuzzy Select.

Select the area of the image you want to be transparent and then press Delete. <- Repeat this step for every desired area of the image.

Edited by warnexus, 16 February 2014 - 04:22 PM.

### #3Aliii  Members

1455
Like
0Likes
Like

Posted 16 February 2014 - 04:23 PM

You mean that the generated explosion sprite has no alpha component? like the white parts are actually white?

Yes, in gimp you select the center of the explosion, invert the selection, choose the "color to alpha" tool(or select by color), click on a white edge and its done.

### #4L. Spiro  Members

24838
Like
2Likes
Like

Posted 16 February 2014 - 04:52 PM

Yes, in gimp you select the center of the explosion, invert the selection

Better to just select the white area outside the explosion from the start, with some amount of fuzziness/anti-aliasing on the selection itself. There is too much contrast on the inside of the explosion to select from there.

L. Spiro

### #5Olof Hedman  Members

5704
Like
2Likes
Like

Posted 17 February 2014 - 11:22 AM

Have you set the proper alpha blending mode with SDL_SetTextureBlendMode?

If your explosion generator can not generate images with an alpha channel, it sure is a sucky explosion generator, and maybe you should change to some other one.

Edited by Olof Hedman, 17 February 2014 - 11:22 AM.

### #6Hawkblood  Members

954
Like
0Likes
Like

Posted 18 February 2014 - 03:03 PM

You definitely need an alpha channel with your textures. Loading each texture individually into Gimp or another editor would take a while to do.

If you have a lot of frames or a lot of explosions, you could create a function that loads all the textures, check the average of each of the color components and then place that value (or half that) into the alpha channel of the texture.

struct COLOR{
COLOR(){};
COLOR(byte cr,byte cg,byte cb, byte ca){b=cb;g=cg,r=cr;a=ca;}
byte b,g,r,a;
COLOR operator * ( CONST byte& other) const;
COLOR operator / ( CONST byte& other) const;
COLOR operator + ( CONST COLOR& other) const;
COLOR& operator += ( CONST COLOR& other);
};
COLOR COLOR::operator+( CONST COLOR& other) const{
int R=r+other.r;
int G=g+other.g;
int B=b+other.b;
int A=a+other.a;
if (R>255) R=255;
if (G>255) G=255;
if (B>255) B=255;
if (A>255) A=255;
return COLOR(byte(R),byte(G),byte(B),byte(A));
}
COLOR COLOR::operator*( CONST byte& other) const{
int R=r*other;
int G=g*other;
int B=b*other;
int A=a*other;
if (R>255) R=255;
if (G>255) G=255;
if (B>255) B=255;
if (A>255) A=255;
return COLOR(byte(R),byte(G),byte(B),byte(A));
}
COLOR COLOR::operator/( CONST byte& other) const{
int R=r/other;
int G=g/other;
int B=b/other;
int A=a/other;
return COLOR(byte(R),byte(G),byte(B),byte(A));
}
COLOR& COLOR::operator+=( CONST COLOR& other){
int R=r+other.r;
int G=g+other.g;
int B=b+other.b;
int A=a+other.a;
if (R>255) R=255;
if (G>255) G=255;
if (B>255) B=255;
if (A>255) A=255;
*this=COLOR(byte(R),byte(G),byte(B),byte(A));
return *this;
}


void FixAlphaToTexture(LPDIRECT3DDEVICE9 pDevice, LPDIRECT3DTEXTURE9 Texture){
LPDIRECT3DSURFACE9 destSurface;
Texture->GetSurfaceLevel(0,&destSurface);

D3DLOCKED_RECT pLockedRect;
destSurface->LockRect(&pLockedRect,NULL,NULL);
COLOR *C=(COLOR*)pLockedRect.pBits;
D3DSURFACE_DESC pDesc;
destSurface->GetDesc(&pDesc);
for (UINT i=0;i<pDesc.Height*pDesc.Width;i++){
int average=C[i].r+C[i].g+C[i].b;
average/=3;
C[i].a=byte(average);
}

destSurface->UnlockRect();
}



Edited by Hawkblood, 18 February 2014 - 03:13 PM.

### #7L. Spiro  Members

24838
Like
0Likes
Like

Posted 18 February 2014 - 05:29 PM

If you have a lot of frames or a lot of explosions, you could create a function that loads all the textures, check the average of each of the color components and then place that value (or half that) into the alpha channel of the texture.

Your implementation should be reversed. White pixels would have the highest alpha and black would have none. It should be whites that are clear, so A = 1 - (AVERAGE / 3).

L. Spiro

### #8Hawkblood  Members

954
Like
0Likes
Like

Posted 18 February 2014 - 06:22 PM

If I add the rgb values and average them, white (255,255,255) would be 255. That would give me complete opacity (not transparent) and anything smaller than (255,255,255) would give me something less than 255 average. Therefore if (128,128,128) would give me 50% transparency.......

### #9L. Spiro  Members

24838
Like
0Likes
Like

Posted 18 February 2014 - 07:22 PM

White (255) is what he wants to remove (from around the edges).

L. Spiro

### #10Hawkblood  Members

954
Like
0Likes
Like

Posted 18 February 2014 - 08:34 PM

The smokey grey edges around all my explosion images stand out way to much because they are not transparent at all, as smoke should be.

The images shown do have white around the edges, but I think it's only because of how he uploaded them. His description (as above) indicates that the "white" around the edge (outside of the explosion itself) is not the issue. The two images are supposedly the same frame of an explosion set, but the one on the left has been modified to take out the "dark gray" around the edge. This tells me the background is irrelevant. His problem is not having transparency within the explosion itself.

Edited by Hawkblood, 18 February 2014 - 08:35 PM.

### #11L. Spiro  Members

24838
Like
0Likes
Like

Posted 18 February 2014 - 09:04 PM

Even if so, it fades from light-grey to black towards the center of the sprite.

The alpha values should be lower given a higher color value.

If an automatic process is desired, I would search specifically for grey pixels (R = B = G), use 1-R to get the alpha, and set the pixel value to [255,255,255].  This is the most correct solution.

L. Spiro

### #12kburkhart84  Members

2886
Like
0Likes
Like

Posted 19 February 2014 - 01:20 AM

If your explosion generator can not generate images with an alpha channel, it sure is a sucky explosion generator, and maybe you should change to some other one.

This is what I was going to say.  It is also possible that you may have some settings messed up.  I doubt you are using Particle Illusion(since it isn't free that I know of), but it has specific settings for things that control how strong the alpha is, and even the particles themselves can be set to affect how much alpha gets into the final images.

The other thing I was going to say...is there any reason why you haven't implemented a particle system.  It isn't near the undertaking as some people make it out to be.  Also, depending on your engine(or what APIs if any) you are using, you may have such a system already available.  You didn't specify what you were using so I can't help directly there.  Doing your own particle explosions has many advantages though.  Each one can be slightly different.  You save the image set(texture memory, etc...) since it is done at runtime.  You can easily modify effects for bigger/smaller explosions.  And if you have a good particle system coded, you can add many more particle effects to things you might not have planned to add them too, like exhaust from ships, trails from bullets, etc...

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.