7

I have the next process:

 - draw background
 - draw objects and blend with background (1)GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA
 - draw particle effect with blending (2)GL10.GL_SRC_ALPHA, GL10.GL_ONE in order to highlight overlapping particles

Problem - when I draw particle they are additionally blended with background and becomes very bright.

Simply what I need is to blend particles with (2) and than all together to blend with background using (1).

Not working solutions:

  • Drawing effect to a texture and than applying it works fine...but extremely slow.
  • Drawing particle effect first and than background, it look ok...but I can not draw scene object than because they need to be between bg and effect

Here is screen to show the difference. On the right desired result, on the left particles are blended with background.

img:

enter image description here

I will appreciate any help...

Latest Updates: I was able to get the color I want...but... (Seems this way will move me nowhere) I have rendered background with alpha = 0 and than use blend Function from GL11Ext: glBlendFuncSeparate(GL10.GL_SRC_ALPHA, GL10.GL_DST_ALPHA, GL10.GL_ONE, GL10.GL_ONE);

GL10.GL_SRC_ALPHA, GL10.GL_DST_ALPHA - the colors are blended only if they have alpha(bg dont have now)

GL10.GL_ONE, GL10.GL_ONE - alpha is set to maximum for all written particles to simulate additive blending

enter image description here

It works fine as you can see...except the black color filling area where particles image has alpha 0..and whats bad that in result image that black color has alpha 1 so I can not replace it in any way...

EDIT_2 General problem in simple words: I need to draw a red(0xff0000) glowing(additive blending) effect. On black background it is ok, but if I would take green(0x00ff00) than the result color would be close to 0xffff00

Any ideas?

Yuriy
  • 817
  • 1
  • 7
  • 17
  • Would rendering to a separate frame buffer work? Do you additive blend of all your particles in a full transparent frame buffer then do a normal alpha blend of that frame buffer onto your main scene. – TurqMage Mar 22 '11 at 19:01
  • Yes, it works. But very slow, I loose near 20fps only switching the framebufferes – Yuriy Mar 25 '11 at 14:50

3 Answers3

3

GL10.GL_SRC_ALPHA, GL10.GL_ONE in order to highlight overlapping particles

There is no other way than additive blending to avoid the need of sorting particles. If you still want to stick with this to avoid overlapping of the particles I suggest you to inject a bleding controll into the rendering so you can reduce brigthness of the rendered particles or you can reduce the brightness of the particle texture.

Drakk Lord
  • 96
  • 3
  • I have tried to reduce brightness of the particle texture, but it is not working, texture is mostly with red color(close to 0xee) and low amount of geen, blue. During blending with bg red is increased only a bit because it is almost maximum, but green and blue are increased significantly. Because of that color is broken. – Yuriy Mar 15 '11 at 08:26
  • Could you explain what you mean by "to inject a bleding controll into the rendering so you can reduce brigthness of the rendered particles" – Yuriy Mar 15 '11 at 08:27
  • I assume you're using ES 1.0, there you can do a simple multipy by setting the glColor* to a desired value, it multipies with the color you set with texture color giving you fine controll over the rendered colors. So setting glColor4f(0.5,0.5,0.5,1.0); will reduce the textures brightness to half. – Drakk Lord Mar 15 '11 at 09:41
  • Currently I am using glColor for particles to add fadeout and color change during lifetime. I have tried to play with it..but the problem is the same as changing texture color - it is reducing brightness, but the color is still broken due to mix with bg. – Yuriy Mar 15 '11 at 11:09
  • In my own engine I implemented this with additive blending + alpha belnding + turned off depth writing ( http://i408.photobucket.com/albums/pp168/DrakkLord/TeaRsYsEngine_particles.png ). You should try to make a simple alpha blending first with glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) to get the desired blending result. – Drakk Lord Mar 15 '11 at 13:31
  • But simple alpha blending can't provide the glowing effect I need..as far as I know(and I have checked that). In your engine when you set different background you should also get the same problem I guess..if you are not using any tricks. – Yuriy Mar 15 '11 at 14:11
  • Already told you the tricks I use. Could you edit your question maybe I get it wrong, what kind of blending you need, what type of textures you use, whats in the background does it have alpha written etc.? – Drakk Lord Mar 15 '11 at 18:39
  • Ok..the easiest way to show my problem - if I could ask you to make a simple simulation in you engine. On the screenshot you posted before I see small red particle effect on the left. Could you try to get exactly the same effect(red), but on green background(rgb - 0x00ff00) – Yuriy Mar 15 '11 at 19:38
1

You could use glAlphaFunc( GL_GREATER, 0 ) to reject the alpha=0 fragments from the particles. Remember to glEnable( GL_ALPHA_TEST ) first though.

ryanm
  • 2,979
  • 18
  • 22
  • Good idea Ryanm, it helps to remove black pixels..but still there is a problem. There are lots of pixels at the edges of effect that has very low alpha, but not zero. Those pixels should be blended with background like GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA. If I would have shaders it would be simple than..but here with 1.1 only... – Yuriy Mar 18 '11 at 13:44
0

Would rendering to a separate frame buffer work? Do you additive blend of all your particles in a full transparent frame buffer then do a normal alpha blend of that frame

TurqMage
  • 3,321
  • 2
  • 31
  • 52