Search code examples
javascriptimage-processingfilterdistortionoculus

what ist the correct Oculus Rift barrel distortion radius function?


i want to implement the barrel shader for the oculus rift in javascript.

according to this video (http://youtu.be/B7qrgrrHry0?t=11m26s) the radius function for barrel distortion is:

newr = 0.24*r^4+0.22*r^2+1

The result:

Reference Image: enter image description here After Shader: enter image description here

if i change the function to newr = r i get the orginal image.


If I set the function to: newr = 0.022*r^2 i get:

enter image description here This one is close but not the right solution (tested with oculus)

So its not the fault of the programm...the radius function is the problem.

Here you can try it in a fiddle: http://jsfiddle.net/s175ozts/2/

Why does the orginal function not work??

thanks :)


Solution

  • After trying a lot of stuff... i finally got the solution. The trick was to normalize r first and then multiply the barrelfunction with orginal r

    var sf = pr / rMax; //Scaling factor
    var newR = pr*(0.24*Math.pow(sf,4)+0.22*Math.pow(sf,2)+1); //barrel distortion function
    

    See fiddle here: http://jsfiddle.net/s175ozts/4/

    Result: enter image description here