Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question What exactly is the displayMatrix?

Discussion in 'AR' started by EdwardAndy, Feb 6, 2021.

  1. EdwardAndy

    EdwardAndy

    Joined:
    Jul 26, 2020
    Posts:
    20
    I want use ARCameraFrameEventArgs.displayMatrix to map point from CpuImage to ScreenSpace.
    I thought the displayMatrix can map screen normalized space to cpu image normalized space, but when I test for it, I found the displayMatrix can't do it exactly!
    My phone screen resolution is 1080*2340, and I set ARCameraConfig to 640*480, and my ScreenOrientation is Portrait.
    Then I get a displayMatrix :
    0.00000 1.00000 0.00000 0.00000
    -0.82051 0.00000 0.91026 0.00000
    0.00000 0.00000 0.00000 0.00000
    0.00000 0.00000 0.00000 0.00000
    I change the displayMatrix for multiplying vector
    0.00000 1.00000 0.00000 0.00000
    -0.82051 0.00000 0.91026 0.00000
    0.00000 0.00000 1.00000 0.00000
    0.00000 0.00000 0.00000 1.00000
    And then, I test points (0,0,1,1) (0,1,1,1) (1,1,1,1) (1,0,1,1) which are the corners in screen normalized space, and the results are (0,0.91,1,1) (1,0.91,1,1) (1,0.089,1,1) (0,0.089,1,1).
    It means the points(0,0) (0,2340) (1080,2340) (1080,0) in screen has been map to (0,436.8) (640,436.8) (640,42.72) (0,42.72) in CpuImage.
    But it's incorrect, 'cause screen's ratio is 6:13 and CpuImage's ratio is 6:8, so screen resolution 1080*2340 has been scale and rotate to 640*295.38 in the vertical center of CpuImage. So (0,0) (0,2340) (1080,2340) (1080,0) in screen should be map to (0,387.69) (640,387.69) (640,92.31) (0,92.31) in CpuImage.

    BTW: If I change ARCameraConfig from 640*480 to 1280*720, it's rate has been changed from 4:3 to 16:9, but the displayMatrix is the same! It's strange!

    So, what exactly is the displayMatrix?
     
    Last edited: Feb 6, 2021
    FrankvHoof and KirillKuzyk like this.
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,744
    ROBYER1 and KirillKuzyk like this.
  3. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,399
  4. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,744
  5. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,744
    This would be better asked over on our Shader Graph forums. :)
     
  6. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,399