Use oblique frustum to render split screen

Hello,

I am trying to achieve a split screen effect where two cameras each renders half of the screen (left and right) using a oblique frustum.
I made a camera script that modifies the projection matrix and view port rectangle before each render call in OnPrecull.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Camera))]
public class CrossScreenCamera : MonoBehaviour {

    // screenRatio is a number between 0 and 1. 0.5 indicates right camera renders the right half of the screen and left camera renders the left half of the screen; 0 indicates right camera renders the whole screen and 1 indicates left camera renders the whole screen
    public float screenRatio = 0;
    public bool isRightHalf;
    private float m00 = 0;
    private float m02 = 0;

    // Use this for initialization
    void Start () {
        screenRatio = InGameGUI.splitScreenRatio; // get this value from a GUIslider
        if(isRightHalf){
            m00 = 1.0f / (1.0f - screenRatio);
            m02 = screenRatio / (1.0f - screenRatio);
            camera.rect = new Rect(screenRatio, 0, 1.0f - screenRatio, 1.0f);
        }
        else{
            m00 = 1.0f / screenRatio;
            m02 = (screenRatio - 1.0f) / screenRatio;
            camera.rect = new Rect(0, 0, screenRatio, 1.0f);
        }
  
        SetSplitScreen (m00, m02);   
    }

    void OnPreCull(){
        screenRatio = InGameGUI.splitScreenRatio;
        camera.ResetProjectionMatrix ();
        if(isRightHalf){
            m00 = 1.0f / (1.0f - screenRatio);
            m02 = screenRatio / (1.0f - screenRatio);
            camera.rect = new Rect(screenRatio, 0, 1.0f - screenRatio, 1.0f);
        }
        else{
            m00 = 1.0f / screenRatio;
            m02 = (screenRatio - 1.0f) / screenRatio;
            camera.rect = new Rect(0, 0, screenRatio, 1.0f);
        }
        SetSplitScreen (m00, m02);

    }

    void SetSplitScreen(float m00, float m02) {

        Matrix4x4 mat = camera.projectionMatrix;
        mat[0, 0] *= m00;
        mat[0, 2] = m02;
        camera.projectionMatrix = mat;
    }



}

If my calculation is correct, when screenRatio is 0.5, the viewing frustum of the left camera, for example, should be exactly the left half of its original frustum, and since I also modified its viewport rectangle to (0, 0, screenRatio, 1.0f), I should get the rendered image on the left half of the screen. However, my image looks stretched horizontally. When screenRatio is any number other than 0.5, the two images rendered by the left and right camera break in the middle.

Could somebody tell me where I did wrong and how oblique frustum should be used in combination with viewport rectangle? Or should I use a different way to do this altogether?

Thank you so much!

Hao


bump

Could anyone please help me with this issue? Thx!