开发者

OpenglES blending particles but not background

I hav开发者_JAVA技巧e 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:

OpenglES blending particles but not background

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

OpenglES blending particles but not background

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜