Best practice for particle effects over bright background?

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Best practice for particle effects over bright background?

Postby Obli » Thu Jun 21, 2012 1:18 pm

Hi guys,

I was wondering if anyone ever tried to draw a particle effect over a bright background (worst case: white background).
Actually, particle effects use additive blending (src: SRC_ALPHA, dst: ONE), and thus blend with the background.
It doesn't matter when the background is dark (that's why every particle editor uses a dark background), but the more bright the background is, the less visible the effect will be.

You can see an illustration of the issue in this topic, or in real-time by changing the background of this flash editor to white.

The suggestion to cope with that is often to render the effect to a transparent off-screen image, and then to draw this image to the screen with common blending. How would you do that with libgdx (I never had to work with off-screen images)? Using a pixmap? I guess it could work for small effects. Large ones could kill performances quite fast maybe (I may be totally wrong though).

Thanks for any tips.
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: Best practice for particle effects over bright backgroun

Postby cuellarjmcg » Mon Jun 25, 2012 5:46 pm

I would also like to know a solution to this. Somehow, namek (view this post: viewtopic.php?f=11&t=3467) made it work using FrameBuffer (but I guess that binds you to GLES 2.0?).
cuellarjmcg
 
Posts: 215
Joined: Tue Feb 21, 2012 8:57 pm

Re: Best practice for particle effects over bright backgroun

Postby Obli » Wed Jun 27, 2012 9:46 am

Using the framebuffer works, but the result is not the same under a black background, which is quite strange:

Image

I still need to figure out what causes this difference. The code I used is as follows:

Code: Select all
if (renderToTexture) {
   frameBuffer.begin();
   Gdx.gl.glClearColor(0, 0, 0, 0);
   Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}

batch.setProjectionMatrix(camera.combined);
batch.begin();
effect.draw(batch, Gdx.graphics.getDeltaTime());
batch.end();

if (renderToTexture) {
   frameBuffer.end();
   batch.getProjectionMatrix().setToOrtho2D(0, h-1, w, -h);
   batch.begin();
   batch.draw(frameBuffer.getColorBufferTexture(), 0, 0);
   batch.end();
}
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: Best practice for particle effects over bright backgroun

Postby Obli » Wed Jun 27, 2012 2:31 pm

I found the answer: in the framebuffer, the background is cleared to transparent (which is mandatory), while a standard GL context always clears to an opaque color, no matter what. Therefore, the stuff drawn in the buffer is not blended in the same way as it is in the main context. There's no real way to prevent that though.

Thus, I guess that the soluion is to put the real game background in the editor and to design the effect from there.
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: Best practice for particle effects over bright backgroun

Postby cuellarjmcg » Wed Jun 27, 2012 3:09 pm

Nice O.o Are you using the Particle Editor from libgdx or another one?

And how is perfomance? Is it good?
cuellarjmcg
 
Posts: 215
Joined: Tue Feb 21, 2012 8:57 pm

Re: Best practice for particle effects over bright backgroun

Postby Obli » Wed Jun 27, 2012 3:14 pm

I made my own particle system API and editor (it was before Nates made several improvements on the libgdx one).
I did not try the framebuffer trick in a game yet, so can't really speak about performances, but I guess they may get a small hit :)

BTW, I found that tutorialto make an awesome explosion effect. It's in 3D, but it should be doable in 2D. i'll try :)
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: Best practice for particle effects over bright backgroun

Postby cuellarjmcg » Wed Jun 27, 2012 3:20 pm

Ok, thanks for the answer :D and the 3D explosion effect looks neat O.o
cuellarjmcg
 
Posts: 215
Joined: Tue Feb 21, 2012 8:57 pm


Return to General Development

Who is online

Users browsing this forum: No registered users and 2 guests