Skip to content

Instantly share code, notes, and snippets.

@Endox
Endox / OculusPreWarp
Created February 10, 2013 18:21
Oculus Rift lens distortion correction fragment shader snippet in GLSL
// Exact distortion parameters (a, b, c) are not known yet, these are just placeholers
float a = 0.20f;
float b = 0.00f;
float c = 0.00f;
float d = 1 - (a + b + c);
// Calculate the source location "radius" (distance from the centre of the viewport)
// fragPos - xy position of the current fragment (destination) in NDC space [-1 1]^2
float destR = length(fragPos);
float srcR = a * pow(destR,4) + b * pow(destR,3) + c * pow(destR,2) + d * destR;