here is the new version:
download
I adjusted some minor things and renamed the “gradient protection” parameter to “smoothness”. but the major point is that the new version now prevents these weird colors shifts rAA sometimes produces that torridgristle reported. in small doses though it actually helps rAA achieving some of its erosion and blending effect. so there is a new parameter called “deviation”. it basically determines how high the error tolerance is.
here is an example. this is maybe not a game where you wanna use the filter but it demonstrates the issue well. notice the weird pixels in the faces of both characters.
old version

new version (deviation = 1.0)

let me show you the code:
float3 res2x(float3 pre2, float3 pre1, float3 px, float3 pos1, float3 pos2)
{
float d1, d2, w;
float3 a, m, t, t1, t2;
float4x3 pre = float4x3(pre2, pre1, px, pos1);
float4x3 pos = float4x3(pre1, px, pos1, pos2);
float4x3 df = pos - pre;
m = (px < 0.5) ? px : (1.0-px);
m = RAA_SHR0 * min(m, min(abs(df[1]), abs(df[2]))); // magnitude
t = (7 * (df[1] + df[2]) - 3 * (df[0] + df[3])) / 16; // tilt
a = t == 0.0 ? 1.0 : m/abs(t);
t1 = clamp(t, -m, m); // limit channels
t2 = min(1.0, min(min(a.x, a.y), a.z)) * t; // limit length
d1 = length(df[1]); d2 = length(df[2]);
d1 = d1 == 0.0 ? 0.0 : length(cross(df[1], t1))/d1; // distance between line (px, pre1) and point px-t1
d2 = d2 == 0.0 ? 0.0 : length(cross(df[2], t1))/d2; // distance between line (px, pos1) and point px+t1
w = min(1.0, max(d1,d2)/0.8125); // color deviation from optimal value
return lerp(t1, t2, pow(w, RAA_DVT0));
}
the tilt vector is now mixed between one that is simply clamped channel wise (t1) and one whose length is adjusted (t2) to satisfy the limits given by m. assuming that an optimal interpolation between px and pre1 is on the line (px, pre1), we can determine the error by calculating the distance from that line to the result produced by the tilt vector px-t1 by using some vector magic (*). we do the same with the right neighbor, pick the maximum and use that as the mix factor between t1 and t2 where we use our new parameter as an exponent to adjust the behavior. the default value is 1.0. if you insist on using this filter for systems such as GameBoy or NES you might wanna lower the value.
(*) reference:
http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
@hunterk
could you help me out again with the upload and shader conversion? uh, just noticed… you said there was something wrong with the slang version, is it still happening? btw there is still this bugfix in the vertex shader for AMD cards. I don’t know if this is still necessary, I just took that part over from Hyllian.