Blending the edges of a explosion

Started by
10 comments, last by kburkhart84 10 years, 1 month ago

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.

[attachment=19968:example.png]

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.

Advertisement

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.

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.

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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.

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();
}

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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

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

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


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.

This topic is closed to new replies.

Advertisement