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:

    在这里输入图像描述

    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

    在这里输入图像描述

    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?


    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.


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


    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

    链接地址: http://www.djcxy.com/p/5462.html

    上一篇: 如何永久删除整个团队的大文件

    下一篇: OpenglES混合粒子,但不是背景