Soundbomber's picture

Blending Outlines

Does anyone know of a blending combination that would blend (or antialias) a line with its background but not with other objects in the scene?
I have a number of outlined polygons which, depending on the viewpoint, could all appear aligned behind each other. When this is the case the outlines (when using conventional blending) appear darker than they would if they were not aligned, presumably because each line is being blended with the next.
Anyone any pointers?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
objarni's picture


Yeah I've stumbled into the outlining problems too - my boss wanted semitransparent solid surfaces, with anti-aliased outlines. I'm still not 100% satisfied with the result, but I tried various things too like you, and I think I came to a reasonable technique.

IIRC I mixed some different things to get the output, in this order:

1. The red lines against the background first of all, with depth read/write so they get sorted against the solids. Notice their fade-to-black antialising, specifically how that looks wrong ontop of the bottom surface, but OK against the black background
2. The surfaces are drawn one before the other:
2.1. The outline is drawn without any blending, and 1.5 line thickness
2.2. The surface is drawn semi-transparent, using 50% alpha-color/blending, and depth read/write
3. The green lines are drawn with blending without depth read/write since they are supposed to be very clear and visible

TransparencyAliasing.png41.86 KB
objarni's picture


Actually, thanks for forcing me to think about this again ;)

Look at the new screenshot, the outlines look much better now! I draw them using blending, AFTER the surfaces. The reason I didn't do that before was because I was using the Line primitive, and drawing line-per-line with thick lines made "endpoints" quite visible.

Using Line-loops instead, made the outline smooth as silk!

TransparencyAliasing2.png44.39 KB
Soundbomber's picture


Any pointers on how to implement FSAA? (Bearing in mind I'm using vb)


Your screenshot looks spot on! Would this work with opaque solids? My best results so far have been achieved by drawing all solids first then all outlines, using depth testing and blending. My geometric objects dont support lineloops directly, I have a number of "stop/starts" is there a way of mixing mostly lineloops with a couple of line primitives? Would I just have to render them as separate objects?

objarni's picture

I guess they would.

1. Draw all opaque surfaces
2. Draw all outlines, with line thickness. Change the Depth-test to less-or-equal, or you will see aliasing effects because of the line-thickness (outlines/surfaces will "fight for precedence"). You might want to look at the Polygon offset functionality of opengl too:

Update: I see in that FAQ that less-or-equal will not solve the problem at all. Read that FAQ I think you will get great advice from there. The problem is "z fighting" because the primities are co-planar (lie in the same 3d-plane) and lines/triangles are rendered using different algorithms, thus producing slightly different z-values (round-off errors etc.)

Soundbomber's picture

This is exactly the approach I have used, implementing polygonoffset to remove the z-fighting. I think one of the effects of having depth testing on (not sure about this though) is that at different zoom levels I am seeing unwanted artefacts (see attached).
On View1, the horizontal line for the gray object is drawn correctly in relation to the solid. On View2, the solid seems to be just outside of the line giving a blurred effect. This may be due to the antialiasing of the line.
You may think that I am being overly "picky" but at lower zooms and with many smaller objects, the effect can be quite annoying. Especially when you know the kind of graphics that are possible.
Any ideas on the Line-loop/line scenareo?

View2.PNG4.19 KB
View1.PNG4.87 KB
the Fiddler's picture

You can set a FSAA GraphicsMode by specifying a non-zero number for the "samples" parameter. Unfortunately, OpenTK ignores this setting (bug #917: [Graphics] FSAA parameter is ignored).

The alternative is to force FSAA through your drivers (use nvidia control panel, ati control center, intel settings etc). If the result is good enough quality-wise, it's simply a matter of OpenTK gaining native support.

The third alternative, namely to use a multisample FBO (renderbuffer), is probably not worth it unless you use FBOs already.

objarni's picture

Hmm. If you use one-pixel-wide outlines, I think you will have trouble getting anti-aliasing plus avoiding the "between pixels" effect View2.PNG shows.

How does 1.5 or even 2 pixel wide lines look? Use GL.LineWidth(2.0f). I don't remember if there is any GL.Enable(..) call necessary for that thick lines to work.

Soundbomber's picture

Yes, it does work with thicker lines but then the 'line ends' are more visible and some of the smaller more intricate objects don't look so good.
To use a line-loop rather than a line primitive type, would I have to render them separatley using BeginMode.Lines / BeginMode.LineLoop?

the Fiddler's picture

Yes, you need to restart primitives when you change primitive type.

objarni's picture

Yes, the big visual improvement for me was changing from Lines to LineLoop. I did not expect that -- I thought the difference was only the data format sent to OpenGL, and not the visual result. It was pure luck that I tried it out! :)

Of course only works for closed polygons - but I guess you have closed outlines just like in my case?