Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenglES blending particles but not background

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?

like image 770
Yuriy Avatar asked Mar 14 '11 18:03

Yuriy


1 Answers

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.

like image 160
Drakk Lord Avatar answered Sep 30 '22 01:09

Drakk Lord