View Full Version : blending function problem with halo-effects

09-15-2009, 08:25 AM
Hi. I'm currently trying to render some visual links (lines) with a nice halo-effect.

My lines are produced as quadstrips. What I'm trying to do now is to render the line twice, the second time with a higher width and less alpha.

This looks OK, but my problem is the following: At the nodes where one line is splitted up into many, the halo get's too opaque. This is because there are many lines on top of each other, so the alpha values are adding up.

Here is a picture. Or three pictures in one. ;)
http://img11.imageshack.us/img11/8564/haloforum.th.png (http://img11.imageshack.us/i/haloforum.png/)
(you should be able to klick on the thumbnail to open it at full size)

The first picture is without halo, so you can see where the lines split up and what causes the problem. The other two pictures show the unwanted effect, with and w/o comments.

I hope this gives a good picture of my problem. I want to get rid of this effect or at least reduce it to a maximum. I guess this should be manageable through blending functions. I already tried some, but couldn't get the wanted results.

Maybe you guys can help me. Thanks!

P.S.: I also tried the method described in NeHe turoials (lesson 36, radial blurr) but didn't get this to work. There are some problems, because the lines are not drawn at once and... so the described method above is how I want to solve this problem now. I already spent too much time on the render-to-texture approach. Many thanks guys.

09-15-2009, 08:43 AM
You could use the stencil buffer. Write to the stencil buffer when you add a halo, then when you draw the next one, make sure that you did not already draw a halo there.

Ilian Dinev
09-15-2009, 08:57 AM
Just an idea, using some extensions I have no experience with: glBlendEquationEXT with GL_MAX_EXT . Clear a RGBA FBO to (0,0,0,0). draw the yellow stuff on it with the gl_max_ext blending mode. Draw that fbo's texture onscreen via regular alphablending.

The stencil approach might not be able to handle some artifacts even if you make it 8-bit with comparison+conditional pass, I think.

09-15-2009, 11:02 AM
Hey guys, thanks for your tipps. I will try these tomorrow and will report back in.
(Tomorrow because of the fact that I'm european and Champions League Group Stage starts in 30 minutes ;) )

09-16-2009, 10:29 AM
Couldn't get this to work so far. glBlendEquationEXT isn't supported by JOGL (I'm programming in Java and use the JOGL Binding).

Ilian Dinev
09-16-2009, 01:24 PM
If GL_MAX and glBlendEquation (which have been added to core) are inaccessible, then the post-process method is your only way.

09-16-2009, 05:57 PM
The proposed stencil idea will work very nicely to prevent overdraw on the transparent lines. You will have to draw ALL lines of a given transparency with the requisite stencil write and test. Then clear or change the reference value for the next width & transparency.

Zbuffer would also work.