Pimax distortion editing

So if anyone wants to try editing the distortion params himself, here’s how to do it. First of all the distortion parameters are stored in tables inside the pi_server.exe file, which is located in C:\Program Files\Pimax\Runtime. You can not edit directly in this write protected directory, so you first need to copy the file to a directory where you have write rights. So:

  1. Copy/paste pi_server.exe in the same directory and rename the copy “pi_server.org”, for if you want to revert to the original later on. It will ask for admin rights, click yes.
  2. copy pi_server.exe to a directory where you have write rights, like your desktop
  3. open that copied file in a hexeditor like hexworkshop.
  4. The distortion params are stored in config tables. The file contains tables for several HMD’s. For pimax 5k+, search for “Pimax P2 5K Formal” with your hex editor.
  5. Once you located that, you’ve located the table with params for the 5k+. Inside this table look for: “K”:[1.0000,1.0484,1.1042,1.1800,1.2650,1.3450,1.4200,1.4700,1.4900,1.5000,1.5100,1.5100,1.5200,1.5400,1.5670,1.5900,1.6100,1.6260 ]

Those are the distortion params for the 5k+. The first param should always be 1.0000. It seems that the numbers directly after that are the outer edges. The numbers are going from lower to higher, if you change that order, so make one number higher than the next, you’ll see very weird effects. So you should probably make sure that they keep going from lower to higher.

  1. after you’re done editing, save the file. Now go to the services tab in your task manager, stop the “piservicelauncher” service. Then copy the edited pi_server.exe over the original file in your pimax directory and start that “piservicelauncher” and you’ll see the new distortion params in effect! Keep in mind that you need 'large FoV" to see changes on the first few params.

If you want to revert, simply copy back the original pi_server.exe (or if you’ve lost it, re-install pitools)

49 Likes

BTW, for more info on what these params are, google for “CatmullRom” as this is the distortion effect being used. You can also see this link for some info on the 10 point version:

// A Catmull-Rom spline through the values 1.0, K[1], K[2] … K[9]
// evenly spaced in R^2 from 0.0 to MaxR^2
// K[0] controls the slope at radius=0.0, rather than the actual value.

So it would seem that the, in this case, 17 parameters are evenly spaced over the lens. And again, that first param should always be 1.000

11 Likes

And the whole config table for the pimax 5k+:

{ 
    "format_ver": 2,
    "name":"Pimax P2 5K Formal",
    "product":"Pimax P2C",
    "usb_vid":1155,
    "usb_pid":257,
    "default_eye_relief":0.013,
    "use_tracker":"light_house",
    "has_physical_ipd_adjust":true,
    "support_controller_pair":true,
    "need_keep_display_alive":true,
    "support_hmd_standby_mode":false,
    "support_hmd_bl_open_close":false,
    "support_hmd_brainwarp":false,
    "support_hmd_parallel_projection_led_indicator":true,
    "min_firmware_version":"2.1.255.147",
    "displays": [
        {
            "enable": true,
            "edid_vid":53838,
            "edid_pid":4121,
            "display_scan_dir": "TB",
            "v_size":0.12096,
            "h_size":0.13608,
            "gap":0.0037,
            "pixel_settle_time":0.0,
            "pixel_persist_time":0.0,
            "display_shutter_type":"global"
        }
    ],
    "render":{
        "double_buffer":false,
        "allow_extend_mode":false,
        "pixels_per_tan_angle_at_center_rate":1.25,
        "lens_separation_to_ipd_rate":0.0669,
        "eyes":[
            {
                "rotate":270,
                "fov_fix_degree":10,
                "lens_fix_degree":-4,
                "distortion_enable":true,
                "view_port": "left",
                "extra_predict_time":0.009
            },
            {
                "rotate":90,
                "fov_fix_degree":-10,
                "lens_fix_degree":4,
                "distortion_enable":true,
                "view_port": "right",
                "extra_predict_time":0.154
            }
        ],
        "fov":{
            "default_fov_level":1,
            "extra":[1,1],
            "extra_fix":[6,6]
        },
        "hidden_area":{
             "enable":true,
             "triangle_split_to":10,
             "triangles-custom-fov":[
                0.4,0.0, 0.0,0.0, 0.0,0.4,
                0.0,0.6, 0.0,1.0, 0.4,1.0,
                1.0,0.2, 1.0,0.0, 0.8,0.0,
                0.8,1.0, 1.0,1.0, 1.0,0.8
             ],
             "triangles_fix-custom-fov":[
                0.4,0.0, 0.0,0.0, 0.0,0.4,
                0.0,0.6, 0.0,1.0, 0.4,1.0,
                1.0,0.2, 1.0,0.0, 0.8,0.0,
                0.8,1.0, 1.0,1.0, 1.0,0.8
             ],
             "triangles":[
                0.2,0.0, 0.0,0.0, 0.0,0.2,
                0.0,0.8, 0.0,1.0, 0.2,1.0,
                1.0,0.2, 1.0,0.0, 0.8,0.0,
                0.8,1.0, 1.0,1.0, 1.0,0.8
             ],
             "triangles_fix":[
                1.0,0.2, 1.0,0.0, 0.8,0.0,
                0.8,1.0, 1.0,1.0, 1.0,0.8
             ]
        }
    },
    "lens":{
        "separation":0.100,
        "adc_to_separation_K":[4960.0,-0.168],
        "diameter":0.072,
        "inner_diameter":0.035,
        "MetersPerTanAngleAtCenter":0.03919542,
        "v_center_off":0,
        "distortion_param":
        {
            "eqn": "CatmullRom17",
            "K":[1.0000,1.0484,1.1042,1.1800,1.2650,1.3450,1.4200,1.4700,1.4900,1.5000,1.5100,1.5100,1.5200,1.5400,1.5670,1.5900,1.6100,1.6260 ],
            "ChromaticAberration":[-0.005,-0.007,0.008,0.023],
            "MaxRadius":  1.4757009417836655,
            "EyeRelief": 0.018
        }
    }
}
7 Likes

It feels like shooting in the dark when changing the distortion params, but I think that’s also what Pimax has been doing to a certain extend. So who knows, with some tweaking it might be possible to improve the distortion.

8 Likes

Maybe some interesting info here to tweak in that config table above @OlivierJT @jojon @Headcool @Machdisk @risa2000 @lonetech @Virtualmisterl @antiflash @McUH and other techies

BTW needless to say, the parameters are init params, and some settings of course will be overwritten

8 Likes

This would be x1000 more perfected if this could be adjusted while wearing the hmd, and also not such static designated areas. It should be like using “liquify” in photoshop where you can slide over any part of an image. If I were them I’d be making a personal software to do this. This would be of immense benefit to people with eye issues to be able to correct their own eye distortions.

17 Likes

Great find, sjefdeklerk. Hopefully some smart minds can make some improvements with this.

3 Likes

I will buy a steam game to the person that can further make these as close to perfect as possible.

5 Likes

I suspect it would be trivial to modify this tool which is used to alter the HTC Vive and Vive Pro distortion profile while in VR. We have been using to fine tun the GearVR mod. It’s not perfect as there is only so much you can do by eye and each profile is unique to your own specific HMD but it could be possible to improve on Pimax’s generic/universal profiel they appear to be using right now.

EDIT: Looking over the parameters in the config I found this interesting. I wonder what happens if you set it to true.

“support_hmd_brainwarp”:false,

8 Likes

Great find @Sjef & thanks for the information you gave for people to have a go.
To be honest this is probably beyond me as I’m not a coder & I do not understand how it all works, but I would love to get my head around the whole process.
It’s just maths after that I guess.

1 Like

I think you need a graphic interface.

2 Likes

That’s the K spline for the 5k+? Yeah would be awesome if we could just move those points up/down in VR in realtime. We need a VR coder like @OlivierJT :slight_smile: Then again, I’m not sure if it’s that trivial, thing is that Pimax uses ‘catmullRom17’ as distortion algo, I’m not sure if it’s easy to mod the ‘standard’ ‘catmullRom10’ algo (OSVR) into the catmullRom17 that Pimax uses. But in theory we could just disable distortion in the HMD itself and then code a tool that distorts in realtime, using visuals, to find the optimal settings.

7 Likes

I’ll try it out later. God I hope it works that would be so amazing for me.

1 Like

Yes the 18 points you gave.

From what I ve found on google, catmullrom17 is not a distortion algo, it’s used to smooth curves through interpolation.

It means Pimax is using a limited number of control points (eg 4) then a higher number of points is generated through catmullrom for a smoother distortion profile.

1 Like

The grid here really gives good insight into how much refinement it really takes.
This is a graphic editor using “liquify”.

2 Likes

Hmm it seems to be a ‘distortion equation’, so I figured it’s the main algo to distort oculusvr-sdk/jogl/src/classes/jogamp/opengl/oculusvr/stereo/lense/LensConfig.java at master · sgothel/oculusvr-sdk · GitHub

1 Like

The distortion is done through control points. Catmull rom is a smoothing equation so you don’t have to mess with hundreds points. Or at least this is how I understand it.

2 Likes

On this page:
https://start-x.github.io/relatorio/doxygen/OVR__DeviceConstants_8h_source.html

It lists 3 possible lens distortion types, of which one is that catmullrom10 type. So I’m pretty sure that’s primary distortion function. But how it works, is not exactly trivial, that’s complicated stuff. Either way to us it doesn’t really matter, it’s all about tweaking those 17 points that form the catmullrom spline that you graphed. I’ve messed around with it and got some interesting effects, I’m now actually starting to think that what I used to call ‘lens blur’ actually also might be distortion too since this effect got much heavier after I messed with certain of those 17 points.

3 Likes

Did not mention this before when you said chromatic aberration is a lens thing ( which is strictly true) but colors aberration are supposed to be corrected up to a certain point in the distortion profiles

https://developer.oculus.com/documentation/pcsdk/0.4/concepts/dg-chromatic-aberration/

Discrepancy in the RGB channels vs the real correction needed would result in a more blur image

3 Likes

Does/can a saved configuration file (.json, I presume, judging by the syntax?) contain (…and supplant) all these hardcoded default parameters, or just some? Would be nice if one could avoid hexediting. :7

I guess the notion of (for the moment, at least) individually factory-calibarated headsets is crushed once and for all…

Catmull, huh? Good old Ed. :slight_smile:

I surmise the implementation of the spline-calculating algorithm either prepends an additional 1.0, for K-1, so that the first segment starts out perpendicular to the lens, or copies K1 for use as a mirroring K-1, but wouldn’t know… That would result in 19 points, for 17 segments, but the evenly divisible 16 would kind of have felt a bit “tidier”… :wink:

Quite a few interesting-sounding value names throughout. Sounds like the render mask is defined as a single triangle per corner, each subsequently subdivided into ten segments per side (EDIT: presumably only the long one), and presumably rounded off in the process…

I guess “lens_separation_to_ipd_rate” accounts for the canted screens and lenses (producing the close right triangle side (IPD), from the lens shuttle sliding along its hypothenuse)…

Scan direction top to bottom… and separate “extra predict time” for each eye… I guess that makes it top-to-bottom in portrait orientation (sideways from our view, but given we do see global shutter type in there, we wouldn’t notice :7), with some provisions for brainwarp… then again… is that a whopping 154 milliseconds for the right eye? -Got to be something else, then… :7

Interesting to see eye relief present. The Rift DK1 preferences used to have you dial that in, and it really occurs to me to be something that we really, really should get set appropriately to how close to the lens the relationship between the shapes of our faces, contra that of the facial interface, leaves us, for best distortion correction. :7

Nice to see @wescotte here – maybe he can make sense of it all. :slight_smile:

Wonder whether doc_ok would care to take a brief glance at it.

EDIT: @Frc, Chromatic aberration has its own quartet of values directly after the spline point array. No idea how they work; Maybe two values each for red and blue, which determines how to scale along the spline depending on t and slope, or something…? :7

5 Likes