1
votes

I'm trying to render 2 (light) circles in OpenGL ES in 2D. The middle is white, the border is black. It works fine, as long as they don't overlap:

enter image description here

But as soon as they do, I get this artifact:

enter image description here

I'm using glBlendFunc(GL_ONE, GL_ONE) with blending enabled of course.

What could be causing this? Is there a way to fix it?

I'd like them to blend more like this:

enter image description here

Thanks!

2

2 Answers

1
votes

Are your circles currently linear gradients? You might get less of an artifact if you have a different curve.

Based on your example, though, it looks like you want the maximum intensity of the two circles, not the sum of the intensities. It appears that Apple's OpenGL ES 2.0 implementation support the EXT_blend_minmax extension, which lets you specify that the resulting fragment values should be the maximum of the inbound and existing values. Maybe try that?

0
votes

The result you're seeing is exactly what should come out for linear gradients. Hint: Open up Photoshop or The GIMP draw two radial gradients into two layers and set them to "Addition" blending mode. It will look exactly like your picture.

A effect like what you desire is given with square gradients. If your gradient is in the range 0…1 take the square of the value and draw this. You may apply a sqrt later if you want to linearize the single gradients.

Not that this is something not easily done using the blending stage; it can be done using multiple passes, but then it's actually more straightforward to use a shader to combine passed from two FBOs.