Created
February 10, 2013 18:21
-
-
Save Endox/4750473 to your computer and use it in GitHub Desktop.
Oculus Rift lens distortion correction fragment shader snippet in GLSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
// Calculate the source vector (radial) | |
vec2 correctedRadial = normalize(fragPos) * srcR; | |
// Transform the coordinates (from [-1,1]^2 to [0, 1]^2) | |
vec2 uv = (correctedRadial/2.0f) + vec2(0.5f); | |
// Sample the texture at the source location | |
fragColor = texture(tex, uv); |
Hi, sorry for replying so late. It's not a full code, just a snippet from the fragment shader. It will work if you declare and bind those variables correctly (fragPos
, fragColor
and tex
).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello is this full code?