Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
larspensjo's avatar
larspensjo
Honored Guest
12 years ago

Pincushion distortion transform

The current barrel transform is



where



As I understand it, you use that to transform the UV coordinates you sample from a bitmap. This works fine for deferred shaders. But how is the reverse transformation done? My math is a little rusty, but it looks to me that it would be non trivial. That is, if you are doing forward rendering and simply want to adjust the coordinates of the vertices in the vertex shader.

I realize such a transformation only works if the geometry is "small enough", with risk for artifacts.

3 Replies

  • Your embedded images do not work for me (broken links). Those broken images have rather odd looking URLs:
    http://latex.codecogs.com/gif.latex?%5Cbegin%7Bbmatrix%7Du%5C%5Cv%5Cend%7Bbmatrix%7D%3D%5Cbegin%7Bbmatrix%7Du_0%5C%5Cv_0%5Cend%7Bbmatrix%7D%28k_0+k_1r%5E2+k_2r%5E4+k_3r%5E6%29

    http://latex.codecogs.com/gif.latex?r%3Du_0%5E2+v_0%5E2

    Google chrome reports that it cannot connect to "latex.codecogs.com". Although it uses a different IP address, "www.codecogs.com" is also not responding. Whois reports that it is a UK address, so if it does not have international restrictions, then perhaps their web servers are down for maintenance.

    Regarding your question, you can find the current implementation in the SDK source code. Look in the fragment pixel shader.

    It is based on the "Brown's model" lens distortion correction formula published at Wikipedia, but without the tangential correction (P) terms needed for lens offset:
    http://en.wikipedia.org/wiki/Distortion_(optics)#Software_correction

    When chromatic aberration correction is used, the formula is applied three times, with slightly different coefficients for each of Red/Green/Blue color planes.

    The artifacts I have noticed seem to be caused by doing the lens distortion correction after downsampling instead of before downsampling (as can be determined by the sharp "stair-step" on the curved outer edges of the warped image output when viewed on a desktop LCD display). If performed before downsampling, that curved edge should be smooth, and their should be less blur in the rendered content, especially near the edges.

    One way to prevent this is by using in-game distortion correction by using a (simulated) fisheye lens on the in-game camera, or by using the center part of a spherical reflection, as described by Paul Bourke back in 2004. There is no blur using this method (which I am using in my Ras Pi code). A complication is if you want to do chromatic aberration correction.
  • "geekmaster" wrote:
    Your embedded images do not work for me (broken links).
    Funny, I can't explain that. It looks fine to me, as does the link. Maybe the server is up and running again now.
    Regarding your question, you can find the current implementation in the SDK source code. Look in the fragment pixel shader.
    But that is the barrel distortion, isn't it?
    It is based on the "Brown's model" lens distortion correction formula published at Wikipedia, but without the tangential correction (P) terms needed for lens offset:
    http://en.wikipedia.org/wiki/Distortion_(optics)#Software_correction
    I see, using a negative K1 gives a pincushion distortion. I just have to find what constants to use.
    When chromatic aberration correction is used, the formula is applied three times, with slightly different coefficients for each of Red/Green/Blue color planes.
    I have't got this far yet, and I am not sure it is needed? Well, I had to go and test it with the demo application (OculusWorldDemo). Indeed, there is a distinct color shift at the outer limits of the view field. But I didn't notice until I started to look for it.

    There are three pairs of lenses provided. Do they all have the same chromatic aberration?

    Thanks for the help!
  • "larspensjo" wrote:
    "geekmaster" wrote:
    Your embedded images do not work for me (broken links).
    Funny, I can't explain that. It looks fine to me, as does the link. Maybe the server is up and running again now.
    The images are working for me now too. Perhaps they were temporarily unavailable...

    "larspensjo" wrote:
    But that is the barrel distortion, isn't it?
    Rift pre-warp does apply barrel distortion, to compensate for pincushion distortion in the lenses.

    "larspensjo" wrote:
    There are three pairs of lenses provided. Do they all have the same chromatic aberration?
    They should be identical lenses. The lens cups are different depths to adjust the focus for different people. The distortion coefficients may need adjusting after switching lens sets, but I did not notice much difference other than FoV using when switching to different lens eyecups. The chromatic aberration correction is not perfect in all cases, making color fringing visible is some areas (especially visible in OculusRoomTiny with all those sharp-edged floor tiles) but it is quite good, IMHO.