1
votes

I have found a very large number of similar problems, but none of the fixes are current or seem to work. I am looking to do this myself and not use an asset.

I am creating an augmented reality system in portrait mode where you use the front or rear camera. I have fixed the rotation issue with the cameras already, but the iOS rear camera is mirrored (if I move my finger in from the left it comes from the right on the camera) and the android front camera is the same, but the back is fine.

The device camera feed is placed onto a ui Image object under a canvas that has a plane mesh applied to it. I have also attempted to work with this as a plane and a Raw Image.

Now the Canvas I have is tied directly to the unity game camera and that Canvas has the image object that is casting the device camera feed. Since the plane and image objects are all one sided, if I flip it around I just get a black screen. I need to mirror the device camera feed, not the game object and I have no idea how to do that.

public GameObject CamFeedObj;
WebCamTexture webcam;
WebCamDevice[] devices;

void Start()
{
    platform = Application.platform;
    devices = WebCamTexture.devices;
    webcam = new WebCamTexture(devices[0].name);
    CamFeedObj.GetComponent<MeshRenderer>().material.mainTexture = webcam;

    // Fixes rotation issue
    if(platform == RuntimePlatform.IPhonePlayer){
        CamFeedObj.transform.eulerAngles = new Vector3(0,-90,90);
    }
    webcam.Play();
}
2

2 Answers

3
votes

You can create a simple shader that flips the x coordinates. Another option is to just multiply the x scale of your ui image by -1.

enter image description here

enter image description here

0
votes

I had same problem with Ipad pro. I am using unity version 2019.2.19f1, xcode 11.3.1.

I used plane to render camera and its transformation is as follows: enter image description here

The code snippet i used to flip:

 void OnPreCull()
{
    GetComponent<Camera>().ResetWorldToCameraMatrix();
    GetComponent<Camera>().ResetProjectionMatrix();
    GetComponent<Camera>().projectionMatrix = GetComponent<Camera>().projectionMatrix * Matrix4x4.Scale(new Vector3(1, -1, 1));
}

void OnPreRender()
{
    GL.invertCulling = true;
}

void OnPostRender()
{
    GL.invertCulling = false;
}