Esempio n. 1
0
    //execute every frame
    void Update()
    {
        clippingDisabled = maps.GetClippingDisabled();

        if (!clippingDisabled)
        {
            Matrix4x4 cameraInverseMatrix = Camera.main.transform.worldToLocalMatrix;
            Vector3   position            = cameraInverseMatrix.MultiplyPoint3x4(transform.parent.position);
            transform.position = position;

            Matrix4x4 matrix         = transform.parent.localToWorldMatrix;
            Matrix4x4 expectedMatrix = new Matrix4x4();
            expectedMatrix     = cameraInverseMatrix * matrix;
            transform.rotation = expectedMatrix.rotation;
            // create plane
            plane.SetNormalAndPosition(transform.up, transform.position);
            //transfer values from plane to vector4 avec inversion de la normale en z car repère caméra ingversé
            Vector4 planeRepresentation = new Vector4(plane.normal.x, plane.normal.y, -plane.normal.z, plane.distance);
            // pass vector to shader
            maps.SetClippingPlane(planeRepresentation);
        }
    }