Jump to content
  • Advertisement
Sign in to follow this  
jdean300

Blending the edges of a explosion

This topic is 2072 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 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.

 

Share this post


Link to post
Share on other sites
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. 

Edited by warnexus

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites


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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!