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

Question How can I set correct clip planes for a oblique frustum with orthographic camera?

Discussion in 'General Graphics' started by dccoo, Oct 15, 2022.

  1. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    I'm reading this article about oblique orthographic camera and it presents a way to set the near and far planes as the blue and red planes of this image:


    I want to obtain the exact same effect. I'm trying this:

    Code (CSharp):
    1. void CalculateObliqueMatrixOrtho( ref Matrix4x4 projection, Vector4 clipPlane )
    2. {
    3.     Vector4 q;
    4.     q = projection.inverse * new Vector4(
    5.         Mathf.Sign(clipPlane.x),
    6.         Mathf.Sign(clipPlane.y),
    7.         1.0f,
    8.         1.0f
    9.     );
    10.     Vector4 c = clipPlane * (2.0F / (Vector4.Dot (clipPlane, q)));
    11.     projection[2] = c.x;
    12.     projection[6] = c.y;
    13.     projection[10] = c.z;
    14.     projection[14] = c.w - 1.0F;
    15. }
    16.  
    17. void Start(){
    18.     var projection = Camera.main.projectionMatrix;
    19.     CalculateObliqueMatrixOrtho(ref projection, plane);
    20.     Camera.main.projectionMatrix = projection;
    21. }
    but I have no idea if I'm doing it right. How can I set
    plane
    according to how I want the blue and the red planes to be?