Search Unity

Off Axis Projection --- HELPPPPP

Discussion in 'Scripting' started by nooB, May 12, 2010.

  1. nooB

    nooB

    Joined:
    Oct 4, 2009
    Posts:
    20
    Totally run into a stone wall with this. I believe this is possibly a bug in Unity but need your help to confirm.

    I m working on implementing an off-axis projection to create Phantograms. I am working on creating this in Unity Windows version.
    But here is the issue. I m using render textures to create the effect.

    Two Images are attached to show the problem.

    Image right below this,
    shows the camera without any off-axis projection. Here the render texture plane(shown on bottom right Quadrant among the Scene views) is rendering correctly what I want.

    Image right at the bottom shows the camera with off-axis projection. Now, if you look at the render texture plane(shown on bottom right Quadrant among the Scene views) is not rendering my scene at all.

    The weirdest thing of all is that this works perfectly on a Mac. The issue I m having is on Windows.

    I am attaching a snippet of the code that does this projection. It would be a great great help if you could point out if theres anything wrong with my code or if its a bug in Unity after all.


    Code (csharp):
    1.  
    2. static function PerspectiveOffCenter(left : float, right : float, bottom : float, top : float, near : float, far : float ) : Matrix4x4
    3. {
    4.     var x = (2.0 * near) / (right - left);
    5.     var y = (2.0 * near) / (top - bottom);
    6.     var shear_x;
    7.     var a = (right + left) / (right - left);
    8.     var b = (top + bottom) / (top - bottom);
    9.     var c = -(far + near) / (far - near);
    10.     var d = -(2.0 * far * near) / (far - near);
    11.     var e = -1.0;
    12.  
    13.     var m : Matrix4x4 = Matrix4x4.zero;
    14.     m[0,0] = x; m[0,1] = 0; m[0,2] = a; m[0,3] = 0;
    15.     m[1,0] = 0; m[1,1] = y; m[1,2] = b; m[1,3] = 0;
    16.     m[2,0] = 0; m[2,1] = 0; m[2,2] = c; m[2,3] = d;
    17.     m[3,0] = 0; m[3,1] = 0; m[3,2] = e; m[3,3] = 0;
    18.    
    19.     //m[0,0] = 1; m[0,1] = 0; m[0,2] = 0; m[0,3] = 0;
    20.     //m[1,0] = 0; m[1,1] = 1; m[1,2] = 0; m[1,3] = 0;
    21.     //m[2,0] = 0; m[2,1] = 0; m[2,2] = 1; m[2,3] = d;
    22.     //m[3,0] = 0; m[3,1] = 0; m[3,2] = e; m[3,3] = 0;
    23.     return m;
    24. }
    25.  
    26. function projectionMatrix(isLeftEye : boolean) : Matrix4x4 {
    27.    var left : float;
    28.    var right : float;
    29.    var a : float;
    30.    var b : float;
    31.    var fov : float;
    32.    
    33.    fov = camera.fieldOfView / 180.0 * Mathf.PI;  // convert FOV to radians
    34.  
    35.    var aspect : float = camera.aspect;
    36.  
    37.    a = camera.nearClipPlane * Mathf.Tan(fov * 0.5);
    38.    b = camera.nearClipPlane / S3DV.focalDistance;
    39.    var correction: float = camera.main.transform.position.y+11;
    40.    //var correction = 0;
    41.    if (isLeftEye)      // left camera
    42.    {
    43.       left  = - aspect * a + (S3DV.eyeDistance * 0.5) * b;
    44.       right =   aspect * a + (S3DV.eyeDistance * 0.5) * b;
    45.    }
    46.    else         // right camera
    47.    {
    48.       left  = - aspect * a - (S3DV.eyeDistance * 0.5) * b;
    49.       right =   aspect * a - (S3DV.eyeDistance * 0.5) * b;
    50.    }
    51.  
    52.     return PerspectiveOffCenter(left, right, -a-correction, a-correction, camera.nearClipPlane, camera.farClipPlane);
    53.    
    54. }
    55.  
     

    Attached Files:

unityunity