Shader based Anti-Aliasing (2D filter)

Hello.

Some newer games have been implementing shader based post-process anti-aliasing methods as an alternative to the comparatively more expensive MSAA. I decided to try my hand at writing a 2D filter that implements such a technique, and the results have been quite good.

My method is based on DLAA, which I read about here:

Before I really began work on the filter, I discovered that Martinsh had previously made some shader-based anti-aliasing filters, and DLAA was one of them. I tried out his DLAA filter, and, unfortunately, the results were dissappointing(No offense to you, Martinsh, your shaders are awesome and much appreciated). His filter wasn’t nearly as effective at smoothing out jaggies as the results seen in the link above. So I made my own.

It finds edges and selectively blurs them along their length, removing jaggies. However, I found that it also blurred textures in the process, so I implemented a crude way to attempt to preserve texture detail that involves a bunch of conditional statements. Unfortunately, this significantly reduces performance, going down from 60fps to 40. It’s lightning fast without texture detail preservation. It’s still pretty fast with it, though.

Here’s some screenshots: (Click the thumbnails and then zoom in for a good view)

Comparison between DLAA and no AA:


No AA:


DLAA with texture detail preservation(perhaps not the best example of the effect, but whatever):


Apparently I can only have 3 attachments per post, so I’ll post a .blend in my next post. Please try out this filter on your own scenes, tell me if it works, what framerates you get, and your opinions on the filter in general. Is it good? Not great, but better than no AA? Or is it totally worthless? Personally, I feel that it’s decent.

Update:

Here’s the new versions(both are faster than the original).

Slightly faster:

DLAA3.blend (554 KB)

Slightly higher quality:

DLAA4.blend (555 KB)

Feel free to use them however you like.

Great job laser blaster, thanks a lot for sharing!

Nice! Better than the one DLAA I found and also faster than the FXAA. Thanks for sharing.
I fixed some minor stuff to make it work on ATI cards:
http://dl.dropbox.com/u/11542084/DLAA.blend

Thanks, guys!

I already have a couple of optimisation ideas in mind, so right now I’m working on making a faster version.

Good Filter.
On my Computer, an old-growing Laptop, the Testscene’s Performance dropped from ~216 to ~108, that is 50%.
But well, that is BGE and 2D-Filters, not your Fault. :wink:

However, I tested it on one of my first-best .blends to see how it would look in a more practical Gameplay-Scene, and I found this:


(Click to enlarge!)
There are some black Parts at the Back of those golden Rings, shaded in pure Darkness, but mere thin Lines… and exactly there, where the Atialiasing would inded be needed, there it simply isn’t.
Probably this is just a Matter of tweaking some Values.

However, thanks for this Filter! :slight_smile:

Hi, I just looked at the commit logs, such 2D filters are no longer necessary if you want to have AA in the BGE (don’t take it too hard as you’ve probably worked hard on the filter)
http://lists.blender.org/pipermail/bf-blender-cvs/2012-January/042520.html

Cucumber - AA for blenderplayer and fullscreen … svn merge ^/branches/soc-2011-cucumber -r 38968,38970,38973,39045,40845

In other words, the AA implementation seen in the Cucumber branch is now in trunk. :slight_smile:

Those thin lines are very difficult cases, unfortunately. That’s because the script attempts to detect and preseve textures by looking for one-pixel wide details, or spatial “peaks” and “valleys” of brightness, just like those lines. To properly anti-alias those lines, I’d have to take extra samples and use a more advanced method of detecting textures. That all slows down the filter. I won’t be able to do anything about it unless I’m struck with some new idea.

@Ace Dragon: That’s good news. If I can get this filter to work faster, though(and I think I can), there still might be some value in using it on older computers(or in scenes with heavy use of alpha textures, like a jungle).

Or simply for those who stay true to 2.49. (not me)

Thanks, this is amazing! Works great on my Radeon 5970, martinsh, thanks for the conversion.

I’ve made major progress with the speed of the filter, and added a few quality tweaks. My most highly optimized version has pretty much identical quality, but runs nearly three times faster than the old one, in terms of rasterizer ms. Well, in theory, at least. I did the testing on the default cube scene(identical setups, of course), but in a realistic game scenario, I’ve found the difference in performance to be pretty small. My theory as to why this occurs is that 2D filters in BGE are very bandwidth intesnive, and although the shader itself is much faster, there just isn’t enough bandwidth to go around when there are lots of textured objects filling the screen. But that’s on my 7-year-old computer, so maybe some of you with newer computers will get improved performance.

Here’s the fast one. It has identical quality to the first(plus a couple small tweaks), and gets me 1.5 rasterizer ms in the default cube scene(I get 4.3 ms for the original).

DLAA3.blend (554 KB)

Here’s a slightly higher quality one. It’s better at preserving texture detail, and gives a nicer edge smoothing effect in a few cases. I get 1.9 ms with this one (I think any extra cost is worth the improved quality).

DLAA4.blend (555 KB)

Please note that this filter isn’t especially well suited for low contrast scenes. It detects edges based on local contrast, so the anti-aliasing effect would be weak without manual tweaking.

Has anyone tried out the new versions? I’m interested to see what kind of impact they have on the framerate on some newer computers.

I tryed the newer ones but neither worked. Assuming they need the same ati fixes?

Yeah, they need to be fixed for ati cards. Unfortunately, I have no idea how to do that.