The first step for Edge Antialias is an Edge Detect…

Edge Detect shader
Edge Detect shader

Here the initial fragment shader in GLSL:

uniform sampler2D lightingStage;
uniform sampler2D colorMap;
uniform sampler2D normalMap;
uniform sampler2D lastResultMap;

float IsEdge(in vec2 coords)
{
    float dxtex = 1.0 / 512.0;
    float dytex = 1.0 / 512.0;

    float depth0 = texture2D(colorMap, coords).a;
    float depth1 = texture2D(colorMap, coords + vec2(dxtex,0.0)).a;
    float depth2 = texture2D(colorMap, coords + vec2(0.0,-dytex)).a;
    float depth3 = texture2D(colorMap, coords + vec2(-dxtex,0.0)).a;
    float depth4 = texture2D(colorMap, coords + vec2(0.0,dytex)).a;

    float ddx = abs((depth1 - depth0) - (depth0 - depth3));
    float ddy = abs((depth2 - depth0) - (depth0 - depth4));

    return clamp((ddx + ddy - 0.01) * 100.0, 0.0, 1.0);
}

void main( )
{
    float dxtex = 1.0 / 512.0;
    float dytex = 1.0 / 512.0;

    float delta = IsEdge(gl_TexCoord[0].st);

    // Comment out for harder edges
    delta += IsEdge(gl_TexCoord[0].st + vec2(dxtex,0.0));
    delta += IsEdge(gl_TexCoord[0].st + vec2(0.0,-dytex));
    delta += IsEdge(gl_TexCoord[0].st + vec2(-dxtex,0.0));
    delta += IsEdge(gl_TexCoord[0].st + vec2(0.0,dytex));
    delta /= 5.0;

    // End comment out
    vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
    color.r    = delta;
    gl_FragColor = color;
}

What the hell is that?

uniform sampler2D lightingStage;
uniform sampler2D colorMap;
uniform sampler2D normalMap;
uniform sampler2D lastResultMap;

In my Deferred Rendering pipeline I have a Post-Procesing Stage, totally dinamic, you can add or remove a set of configurable effects and all are processed one by one. lightingStage is the last stage texture, the original before Post-Procesing. The colorMap texture is ALBEDO, normalMap is normals… and lastResultMap is the last texture generated with the last shader in Post-Procesing Stage.