obviousjim/ofxOculusRift — pull request #6 by prisonerjohn (2013-11-12 17:56:30+00:00)
Title: Added chromatic aberration correction to the frag shader.

I think... it looks crisper to me but then again my eyes aren't the best.

I ported over this code, which I found in the [OVR docs](http://static.oculusvr.com/sdk-downloads/documents/Oculus_SDK_Overview.pdf).
```
Texture2D Texture : register(t0);
SamplerState Linear : register(s0);
float2 LensCenter;
float2 ScreenCenter;
float2 Scale;
float2 ScaleIn;
float4 HmdWarpParam;
float4 ChromAbParam;

float4 main(in float4 oPosition : SV_Position, in float4 oColor : COLOR,
in float2 oTexCoord : TEXCOORD0) : SV_Target
{
float2 theta = (oTexCoord - LensCenter) * ScaleIn; // Scales to [-1, 1]
float rSq = theta.x * theta.x + theta.y * theta.y;
float2 theta1 = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq +
HmdWarpParam.z * rSq * rSq +
HmdWarpParam.w * rSq * rSq * rSq);

// Detect whether blue texture coordinates are out of range
// since these will scaled out the furthest.
float2 thetaBlue = theta1 * (ChromAbParam.z + ChromAbParam.w * rSq);
float2 tcBlue = LensCenter + Scale * thetaBlue;
if (any(clamp(tcBlue, ScreenCenter -float2(0.25,0.5),
ScreenCenter+float2(0.25, 0.5)) - tcBlue))
return 0;

// Now do blue texture lookup.
float blue = Texture.Sample(Linear, tcBlue).b;
// Do green lookup (no scaling).
float2 tcGreen = LensCenter + Scale * theta1;
float green = Texture.Sample(Linear, tcGreen).g;
// Do red scale and lookup.
float2 thetaRed = theta1 * (ChromAbParam.x + ChromAbParam.y * rSq);
float2 tcRed = LensCenter + Scale * thetaRed;
float red = Texture.Sample(Linear,o tcRed).r;

return float4(red, green, blue, 1);
}
```

One thing I noticed is that it always returns alpha 1. Is this the behaviour we want? Other options would be to get the min/max/avg of the three looked up pixels.