Yoshiboy's Antialising

From Mount&Blade Modding Wiki
Jump to: navigation, search

Description

Yoshiboy created a simplified variation of the FXAA algorithm, used to mask the jagged edges from rendered polygons without upsampling (that is, rendering a larger image and scaling it down). So it's way faster than traditional AA.

Here you've a video showing as rough preview of the FXAA results:

http://www.youtube.com/watch?v=4GGeg1QGl8Y


Further reference:

http://en.wikipedia.org/wiki/Anti-aliasing


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;
  }
 
}

Source

Source Page and main article: http://www.theorangeduck.com/page/unsharp-anti-aliasing

Preview

unsharp_aa.png

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox