Search Unity

Hardware Display Distortion Correction

Discussion in 'General Discussion' started by dave_m_moore, Mar 23, 2023.

  1. dave_m_moore

    dave_m_moore

    Joined:
    Jul 28, 2016
    Posts:
    39
    Hi,
    Can someone please tell me how Unity manages display distortion correction for common AR/VR hardware such as the HoloLens and other headsets? Am I right in thinking that a Unity Application targeted for one of these platforms performs the display distortion correction (warping) of the left/right images or is this typically done by the hardware itself? Assuming the former, how is Unity configured to provide the correct distortion characteristics for the headset type?

    Thanks for any pointers,
    Dave
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    I'm under impression that unity does not deal with it directly and instead forwards the data to whatever underlying SDK is being used and it handles the distortion. Meaning if you're using Oculus then it knows its own distortion coefficients, what's more distortion is not performed by unity, but by oculus runtime.

    You cannot directly alter distortion coefficients, the best you can adjust is projection and view matrices for each eye, and there are many limitations (trying to set view/projection matrices in VR can easily cause unity to render nothing or produce no effect).

    For VR application rendering generally works like it would in a flatscreen games, meaning each eye gets a normal projection matrix for specific fov. However, both eyes can be rendered at the same time.

    With foveated rendering, situation can be different, but I have no access to such headset.

    The exception is google cardboard. In case of google cardboard (I think it is deprecated, by the way), device parameters are set in a device profile which is provided in a very awkward and roundabout way through a link to a google protocol buffer or something like that.
     
    dave_m_moore likes this.
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    Distortion is done by headset driver or hardware. Otherwise you would have the burden on supporting each device‘s hardware specifics on Unity, and that wouldn‘t be a good approach for both Unity and hardware creators. It just makes more sense to have that distortion correction tied with the hardware and therefore I assume that’s what it is.
     
  4. dave_m_moore

    dave_m_moore

    Joined:
    Jul 28, 2016
    Posts:
    39
    Hi, thanks for your response.

    So what is this SDK? And what is the interface on this SDK? Can I create my own SDK and have Unity use it?

    So alternatively, how could I set a device profile for a custom device?

    Thanks for any pointers,
    Dave
     
  5. dave_m_moore

    dave_m_moore

    Joined:
    Jul 28, 2016
    Posts:
    39
    Thanks for your reply. I understand your reasoning. But surely the device would be using the host's GPU to perform that distortion correction? In which case, Unity must be passing each eye's image frame (via software) to some form of driver software. So where is this interface?
     
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    Device driver and API for interfacing with it. There's no point in making your own SDK, unless you're oculus. Which means "unless you're a well-known VR manufacturer"

    The issue here is that VR headset is not something like an LCD monitor. At least at the moment.

    I believe when people were creating custom headsets, they were using Steam VR to interface with them.

    See, for example, Relativity project:
    https://github.com/relativty/Relativty

    Or google for "DIY VR Headset".
     
  7. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    I'd like to elaborate something. The point of making a custom headset is that so you can play stuff on it. Stuff made by other people. In order for that to happen, the headset has to work through Oculus software or SteamVR.

    You don't have to do it this way, you could absolutely make a completely custom hardware that is seen as a display by an operating system and do everything by yourself on it from scratch, including lens distortion correction.

    However, people won't be able to play existing VR games on this sort of device, because it can't talk to oculus or steamvr.
     
  8. IanHsiao

    IanHsiao

    Joined:
    Apr 13, 2023
    Posts:
    1
    Hi Neginfinity and Dave

    Correct me if I were wrong, Niginfinity is basically saying that it is not doable to alter the distortion coefficient in a Oculus headset.
    I've tried to get the gpu buffer as a texture 2D, from there I can get the distortion map if comparing to the display screenshot. So I believe we can preDistort (counter-distortion) the raw image to achieve the wanted customized distortion result?
    Even better, can we disable the built-in Oculus run-time distortion, and display our own pre-distorted image?

    Thanks.