Search Unity

Problem Camera.CalculateObliqueMatrix

Discussion in 'PSM' started by lavz24, Jun 20, 2014.

  1. lavz24

    lavz24

    Joined:
    Mar 14, 2013
    Posts:
    45
    Hi,

    When i try to use standard assets Water pro, i have a copile error with : Camera.CalculateObliqueMatrix. Doesnt exits in the API.
     
  2. bakanekofr

    bakanekofr

    Joined:
    Feb 28, 2014
    Posts:
    122
    I had this error too. Disabling theses lines seems to work fine, but this could cause issues (none found so far for me).
     
  3. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Hm, I think we may accidentally have included the more recent Unity 4.5 Standard Assets with the Unity for PSM installation.
    In Unity 4.3.x (on which Unity for PSM is currently based) the Camera class did not have the CalculateObliqueMatrix function.

    Instead you need to calculate it manually using

    Code (csharp):
    1.             // Setup oblique projection matrix so that near plane is our reflection
    2.             // plane. This way we clip everything below/above it for free.
    3.             Vector4 clipPlane = CameraSpacePlane( reflectionCamera, pos, normal, 1.0f );
    4.  
    5. // Camera.CalculateObliqueMatrix is not available in Unity 4.3
    6. // 4.5 :    reflectionCamera.projectionMatrix = cam.CalculateObliqueMatrix(clipPlane);
    7. // Instead we calculate it manually :
    8.             Matrix4x4 projection = cam.projectionMatrix;
    9.             CalculateObliqueMatrix (ref projection, clipPlane);
    10.             reflectionCamera.projectionMatrix = projection;
    11.  
    12.             reflectionCamera.cullingMask = ~(1<<4) & m_ReflectLayers.value; // never render water layer
    13.             reflectionCamera.targetTexture = m_ReflectionTexture;
    Code (csharp):
    1.     // Adjusts the given projection matrix so that near plane is the given clipPlane
    2.     // clipPlane is given in camera space. See article in Game Programming Gems 5 and
    3.     // http://aras-p.info/texts/obliqueortho.html
    4.     private static void CalculateObliqueMatrix (ref Matrix4x4 projection, Vector4 clipPlane)
    5.     {
    6.         Vector4 q = projection.inverse * new Vector4(
    7.             sgn(clipPlane.x),
    8.             sgn(clipPlane.y),
    9.             1.0f,
    10.             1.0f
    11.         );
    12.         Vector4 c = clipPlane * (2.0F / (Vector4.Dot (clipPlane, q)));
    13.         // third row = clip plane - fourth row
    14.         projection[2] = c.x - projection[3];
    15.         projection[6] = c.y - projection[7];
    16.         projection[10] = c.z - projection[11];
    17.         projection[14] = c.w - projection[15];
    18.     }
    19.  
    20.     // Calculates reflection matrix around the given plane
    21.     private static void CalculateReflectionMatrix (ref Matrix4x4 reflectionMat, Vector4 plane)
    22.     {
    23.         reflectionMat.m00 = (1F - 2F*plane[0]*plane[0]);
    24.         reflectionMat.m01 = (   - 2F*plane[0]*plane[1]);
    25.         reflectionMat.m02 = (   - 2F*plane[0]*plane[2]);
    26.         reflectionMat.m03 = (   - 2F*plane[3]*plane[0]);
    27.  
    28.         reflectionMat.m10 = (   - 2F*plane[1]*plane[0]);
    29.         reflectionMat.m11 = (1F - 2F*plane[1]*plane[1]);
    30.         reflectionMat.m12 = (   - 2F*plane[1]*plane[2]);
    31.         reflectionMat.m13 = (   - 2F*plane[3]*plane[1]);
    32.    
    33.         reflectionMat.m20 = (   - 2F*plane[2]*plane[0]);
    34.         reflectionMat.m21 = (   - 2F*plane[2]*plane[1]);
    35.         reflectionMat.m22 = (1F - 2F*plane[2]*plane[2]);
    36.         reflectionMat.m23 = (   - 2F*plane[3]*plane[2]);
    37.  
    38.         reflectionMat.m30 = 0F;
    39.         reflectionMat.m31 = 0F;
    40.         reflectionMat.m32 = 0F;
    41.         reflectionMat.m33 = 1F;
    42.     }
     
    Pawl and lavz24 like this.
  4. bakanekofr

    bakanekofr

    Joined:
    Feb 28, 2014
    Posts:
    122
    Actually, my project was made using Unity 4.5, thus using the water pro from 4.5.

    The solution was to create a new scene, delete the water pro folder, then import water pro from the 4.3 PSM Unity. No more errors.
     
    lavz24 likes this.
  5. lavz24

    lavz24

    Joined:
    Mar 14, 2013
    Posts:
    45
    Thank you very much