• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
jdean300

Blending the edges of a explosion

11 posts in this topic

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.

 

0

Share this post


Link to post
Share on other sites

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
1

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.

0

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
2

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
2

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
0

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
0

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

0

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
0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

 

 

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

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0