Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Custom projection matrix : need help finetuning my script and light problem

Discussion in 'General Graphics' started by TomTheoriz, Aug 11, 2016.

  1. TomTheoriz

    TomTheoriz

    Joined:
    Dec 8, 2015
    Posts:
    3
    Hello !

    I'm trying to setup a camera for anamorphic projection (Unity 5.4), which would take the "screen" coordinates in the virtual world and adjust its frustum accordingly.
    I found a script based on the documentation's example of a custom projection matrix and this paper, and tweaked it a little :
    - I replace the "eye position" by the camera's transform position.
    - I added à 180° rotation just before returning the projection matrix because, well, without it the image was upside down.

    I noticed several problems and I can't find a fix so I'm humbly asking the community for help :

    - When the Z coordinates of all the screen corners are equal and the cameras is oriented towards the +z axis, everything behaves as it should :
    Cam1.PNG

    - When the Z coordinates of the screen corners are NOT equal, there is a bug with the lights : depending on the position of the camera, sometimes the light stops abruptly instead of fading normally :
    Cam2.PNG

    - When the Z coordinates of the corners are very different the frustum is not correctly computed, resulting in what seems to be frustum culling bugs. Apart from that the resulting images remains almost correct but the frustum's gizmo is incorrect.
    Further investigation revealed that the problem occurs when the Z value of the camera's position is greater than one side of the screen's Z value (one of the axis of the frustum's gizmo is inverted), and it happens again when it's greater than both screen sides' Z values (the two axes are inverted) :

    Case A : z position smaller than both sides' z position -> OK except light bug
    Cam3_a.PNG
    Case B : z position greater than the first side's z position -> Frustum culling bug (we should the a cube on the left of the image)
    Cam3_b.PNG
    Case C : z position greater than both sides's z position -> Nothing is shown, probably because of culling also
    Cam3_c.PNG

    I'll attach the minimal project file in the next message so you can see by yourself (max 5 files linked per post).
    Thanks a lot for your help !

    Tom
     
  2. TomTheoriz

    TomTheoriz

    Joined:
    Dec 8, 2015
    Posts:
    3
    Here is the project file...
     

    Attached Files:

  3. TomTheoriz

    TomTheoriz

    Joined:
    Dec 8, 2015
    Posts:
    3
    Small update so this post doesn't get burried too quickly, can anyone help please ? :)
     
  4. B_Theoriz

    B_Theoriz

    Joined:
    Jun 17, 2016
    Posts:
    3
    Up, still the same issue in Unity 5.5. Does anybody else had this problem ? Any guess about a potential fix ?
     
  5. hmb3141

    hmb3141

    Joined:
    Oct 8, 2014
    Posts:
    18
    Did you make any progress with this?

    - When the Z coordinates of all the screen corners are equal and the cameras is oriented towards the +z axis, everything behaves as it should :

    I'm not sure it is behaving exactly as expected. In your example project move the cubes so they are positioned 'behind' the screen z position. Then when you move the camera closer to the cubes they will appear to shrink. I am seeing the same with my camera matrix calculations which are almost identical.