Icon ASCII : A Love Letter


Icon My Neural Network isn't working! What should I do?


Icon Phase-Functioned Neural Networks for Character Control


Icon 17 Line Markov Chain


Icon 14 Character Random Number Generator


Icon Simple Two Joint IK


Icon Generating Icons with Pixel Sorting


Icon Neural Network Ambient Occlusion


Icon Three Short Stories about the East Coast Main Line


Icon The New Alphabet


Icon "The Color Munifni Exists"


Icon A Deep Learning Framework For Character Motion Synthesis and Editing


Icon The Halting Problem and The Moral Arbitrator


Icon The Witness


Icon Four Seasons Crisp Omelette


Icon At the Bottom of the Elevator


Icon Tracing Functions in Python


Icon Still Things and Moving Things


Icon water.cpp


Icon Making Poetry in Piet


Icon Learning Motion Manifolds with Convolutional Autoencoders


Icon Learning an Inverse Rig Mapping for Character Animation


Icon Infinity Doesn't Exist


Icon Polyconf


Icon Raleigh


Icon The Skagerrak


Icon Printing a Stack Trace with MinGW


Icon The Border Pines


Icon You could have invented Parser Combinators


Icon Ready for the Fight


Icon Earthbound


Icon Turing Drawings


Icon Lost Child Announcement


Icon Shelter


Icon Data Science, how hard can it be?


Icon Denki Furo


Icon In Defence of the Unitype


Icon Maya Velocity Node


Icon Sandy Denny


Icon What type of Machine is the C Preprocessor?


Icon Which AI is more human?


Icon Gone Home


Icon Thoughts on Japan


Icon Can Computers Think?


Icon Counting Sheep & Infinity


Icon How Nature Builds Computers


Icon Painkillers


Icon Correct Box Sphere Intersection


Icon Avoiding Shader Conditionals


Icon Writing Portable OpenGL


Icon The Only Cable Car in Ireland


Icon Is the C Preprocessor Turing Complete?


Icon The aesthetics of code


Icon Issues with SDL on iOS and Android


Icon How I learned to stop worrying and love statistics


Icon PyMark


Icon AutoC Tools


Icon Scripting xNormal with Python


Icon Six Myths About Ray Tracing


Icon The Web Giants Will Fall


Icon PyAutoC


Icon The Pirate Song


Icon Dear Esther


Icon Unsharp Anti Aliasing


Icon The First Boy


Icon Parallel programming isn't hard, optimisation is.


Icon Skyrim


Icon Recognizing a language is solving a problem


Icon Could an animal learn to program?




Icon Pure Depth SSAO


Icon Synchronized in Python


Icon 3d Printing


Icon Real Time Graphics is Virtual Reality


Icon Painting Style Renderer


Icon A very hard problem


Icon Indie Development vs Modding


Icon Corange


Icon 3ds Max PLY Exporter


Icon A Case for the Technical Artist


Icon Enums


Icon Scorpions have won evolution


Icon Dirt and Ashes


Icon Lazy Python


Icon Subdivision Modelling


Icon The Owl


Icon Mouse Traps


Icon Updated Art Reel


Icon Tech Reel


Icon Graphics Aren't the Enemy


Icon On Being A Games Artist


Icon The Bluebird


Icon Everything2


Icon Duck Engine


Icon Boarding Preview


Icon Sailing Preview


Icon Exodus Village Flyover


Icon Art Reel




Icon One Cat Just Leads To Another

Unsharp Anti Aliasing

Created on Feb. 13, 2012, 7:55 p.m.

While working on trying to implement FXAA I stumbled upon a fairly cool hack for AA which provides some interesting results. It isn't exactly that smart or groundbreaking but it is still useful to know.

The first thing I found was that as it turns out the naive solution of finding the color difference to surrounding pixels and then mixing based upon this difference works surprisingly well. The one main gripe I had with it - which is fairly much the same for all AA aproximations was that it made detailed textures blurry and the whole scene look a bit messy. Even with a good tolerance threshold and some other cheap tricks on top it just wasn't really up to it.

At the same time I was doing this I was playing around with implementing an unsharp mask - a post effect for sharpening the final image. I realised that all of the color difference operations I was doing I seemed to be performing in both shaders. It made sense to combine them into one and see what happens.

Combined into a single shader it sharpens the resultant image and blurs along areas of hard contrast - hopefully edges. Again, the effectiveness of this result surprised me. Sharpening the image ensured that it retained some nice per-pixel details and even though this wasn't all over the image (there were still too many false positives being highlighted as edges), the fact that it had some sections of high detail gave it an overall sharp look. This sharpening also didn't get in the way of the AA effect along edges. Some other unexpected benefits were the removal of the unsharp mask haloing, which you can get around edges, and also the way it works well with cheaper texture sampling methods.

On a good day it can resemble 4x MSAA with an intelligently applied unsharp mask and on a bad day it can create some odd artefacts and blurry texture sections. Overall though - for a very cheap filter it gives some quite impressive results. As always source is free to use/modify/distribute.




vec3 fxaa_unsharp(sampler2D input, vec2 pos, int width, int height) {
  const float sharpen = 0.5;
  const float boundry = 0.1;
  const float alias_scale = 2.75;
  float kernel = 1.0;
  float xoff = kernel / float(width);
  float yoff = kernel / float(height);

  vec3 rgb_ne = texture2D(input, pos + vec2(-xoff,yoff)).rgb;
  vec3 rgb_n = texture2D(input, pos + vec2(0,yoff)).rgb;
  vec3 rgb_nw = texture2D(input, pos + vec2(xoff,yoff)).rgb;
  vec3 rgb_w = texture2D(input, pos + vec2(xoff,0)).rgb;
  vec3 rgb_o = texture2D(input, pos + vec2(0,0)).rgb;
  vec3 rgb_e = texture2D(input, pos + vec2(-xoff,0)).rgb;
  vec3 rgb_sw = texture2D(input, pos + vec2(-xoff,-yoff)).rgb;
  vec3 rgb_s = texture2D(input, pos + vec2(0,-yoff)).rgb;
  vec3 rgb_se = texture2D(input, pos + vec2(xoff,-yoff)).rgb;
  vec3 average = (rgb_ne + rgb_n + rgb_nw + rgb_w + rgb_e + rgb_sw + rgb_s + rgb_se) / 8;
  vec3 difference = rgb_o - average;
  rgb_o = rgb_o + (difference * sharpen);
  difference = rgb_o - average;
  float fdiff = abs(dot(vec3(1,1,1), difference));
  if (fdiff > boundry) {
    float alias_amount = clamp(fdiff * alias_scale, 0.25, 0.75);
    //return mix(vec3(0,1,0), vec3(1,0,0), alias_amount);
    return mix(rgb_o, average, alias_amount);
  } else {
    return rgb_o;



github twitter rss