Off-axis projection problem

I am trying to get off-axis projection working for my scene camera, and can’t seem to get it working. I am on Unity 4.0.1f2.

I am using the PerspectiveOffCenter function provided here: http://docs.unity3d.com/Documentatio...ionMatrix.html

Code:

public static Matrix4x4 PerspectiveOffCenter(float left, float right,
                                                 float bottom, float top,
                                                 float near, float far)
{
      float x = 2.0F * near / (right - left);
      float y = 2.0F * near / (top - bottom);
      float a = (right + left) / (right - left);
      float b = (top + bottom) / (top - bottom);
      float c = -(far + near) / (far - near);
      float d = -(2.0F * far * near) / (far - near);
      float e = -1.0F;
 
      Matrix4x4 m = new Matrix4x4();
      m[0, 0] = x; m[0, 1] = 0; m[0, 2] = a; m[0, 3] = 0;
      m[1, 0] = 0; m[1, 1] = y; m[1, 2] = b; m[1, 3] = 0;
      m[2, 0] = 0; m[2, 1] = 0; m[2, 2] = c; m[2, 3] = d;
      m[3, 0] = 0; m[3, 1] = 0; m[3, 2] = e; m[3, 3] = 0;
 
      return m;
}

My C# script is simply this, and is attached to my only scene camera:
Code:

using System.Collections;
using UnityUtil;
 
public class ARCamera : MonoBehaviour
{
  private Matrix4x4 customProj;
  private float near = 0.05f;
  private float far = 30.0f;
 
  // Use this for initialization
  void Start()
  {
    float left, right, bottom, top;
 
    camera.nearClipPlane = near;
    camera.farClipPlane = far;
 
    left = -0.3f;
    right = 0.1f;
    bottom = -0.1f;
    top = 0.1f;
 
    customProj = MathUtil.PerspectiveOffCenter(left, right, bottom, top, near, far);
  }
 
  // Update is called once per frame
  void LateUpdate()
  {
    camera.projectionMatrix = customProj;
  }
}

This seems to have no effect of my camera frustum. When the player is running, the scene view shows a perfectly symmetric frustum. Setting the projection matrix seems to have no effect.

Anyone know what I might be doing wrong?

Works for me. In either Update or LateUpdate. Check if it’s working at all with just projMat = Matrix4x4.identity;

Then try it with much larger values. You may not be getting the scale correct, so that left/right of -0.3 and 0.1 is working, but is only making a difference of a few pixels. (I set matrix[3,0]=7 which should have jerked the camera sideways, but didn’t appear to do anything. Changing to =20 I could finally see it was pulling to the right, 7 just wasn’t noticeable.)

Then maybe look up the formula again. This is pretty well-known, so probably lots of places to go for the original.

From what I understood left, right, top, bottom, specify the extents of the near plane.

For the number I entered:
left = -0.3f;
right = 0.1f;
bottom = -0.1f;
top = 0.1f;
near=0.05

That should be a pretty off center projection, yet the frustum gizmo in scene view (while running) does not change at all, and the projection to that camera looks no different than the on-axis version, as if my projection matrix was never actually applied.

BTW, does that matrix really need to be set on ever update/lateupdate? Why can it not be set once. Does it have to be set from a script directly attach to the camera or can it be set by another script for that camera but not attached to it?

Is there anything that would cause Unity not to use the matrix?