Search Unity

[HoloLens] Render different layers with multiple cameras.

Discussion in 'VR' started by fronzu, Feb 5, 2018.

  1. fronzu

    fronzu

    Joined:
    Nov 1, 2016
    Posts:
    24
    Hi!

    I already saw this thread https://forum.unity.com/threads/using-multiple-cameras.416890/ which exposed the exactly same problem than mine, but it hasn't been answered since 2016 and a solution were not found.

    I'd like to use two cameras, the second one with the only goal to render some objects over others.

    The problem is that what is rendered by the second camera moves in the opposite direction than my gaze does, like if the camera doesn't move with my head but stays still in the same position and rotation.
    That problem occurs even with a script attached to the second camera that copies position and rotation of the main camera.

    The strange thing is that this method works in editor, which leads me to think the problem has something to do with steroscopic rendering or something managed only by HoloLens.

    Has this problem been solved? I really need that feature.

    Thanks and have a nice day!
     
  2. JasonCostanza

    JasonCostanza

    Unity Technologies

    Joined:
    May 23, 2017
    Posts:
    404
    What are you doing in your script, can we get some more info about how you're retrieving the main camera position/rotation and what not?
     
  3. fronzu

    fronzu

    Joined:
    Nov 1, 2016
    Posts:
    24
    Hi, sorry for the late reply, in the end solved my problem using another solution.

    My script however was something like:
    Code (CSharp):
    1. private void Update()
    2. {
    3. secondCamera.transform.position = mainCamera.transform.position;
    4. secondCamera.transform.rotation = mainCamera.transform.rotation;
    5. }
    I forgot to mention that the second camera was a child of the main camera (which I thought would be enough to make it move and rotate as its parent did), but with or without the script attached, the problem was the same.
     
    Pycorax likes this.
  4. Pycorax

    Pycorax

    Joined:
    May 30, 2016
    Posts:
    2
    @JasonCostanza May I know if your team is still looking into this issue? I'm trying to do the same thing as OP and the problem occurs because the world position and orientation of the device in the real world (obtained by the HoloLens tracking) is being set to the camera's local position and rotation regardless of their parenting. Thus, if I had a child camera attached to the parent camera, they would have the exact same local position and rotation, causing a desync in both cameras.
     
  5. JasonCostanza

    JasonCostanza

    Unity Technologies

    Joined:
    May 23, 2017
    Posts:
    404
    I'm sorry for the late reply, I was out of office for the holidays. Let me forward this to our input team who I think would be the people to look at this now. A lot has changed in a year so we may have a new, better solution.
     
  6. Matt_D_work

    Matt_D_work

    Unity Technologies

    Joined:
    Nov 30, 2016
    Posts:
    202
    so, by putting the second camera as a child of the main camera, you should not have to modify the second camera's position at all. as the main camera's movement and rotation will be applied to its children. so putting the second camera as a child of the main camera at 0,0,0 looking down the Z axis in local camera space would effectively solve the problem.

    the data returned by the hololens is always in "tracking space", not unity world space. so only applying the tracking data in the local frame is the correct result, but i'm not sure if thats what you're seeing? are you using the tracked pose driver to drive the headset position? what does your hierarchy look like?

    a video would help :) or the project files :)
     
    JasonCostanza likes this.
  7. yugen1

    yugen1

    Joined:
    Dec 17, 2019
    Posts:
    4
    Code (CSharp):
    1.  private struct PointInSpace
    2.     {
    3.         public Vector3 Position;
    4.         public float Time;
    5.     }
    6.     private Queue<PointInSpace> pointsInSpace = new Queue<PointInSpace>();
    7.     void FixedUpdate()
    8.     {
    9.         // Add the current target position to the list of positions
    10.         pointsInSpace.Enqueue(new PointInSpace() { Position = maincam.position, Time = Time.time });
    11.         // Move the camera to the position of the target X seconds ago
    12.         while (pointsInSpace.Count > 0 && pointsInSpace.Peek().Time <= Time.time - delay + Mathf.Epsilon)
    13.         {
    14.             transform.position = pointsInSpace.Dequeue().Position;
    15.             //maincam.enabled = false;
    16.             //cam.enabled = true;
    17.            
    18.         }
    19.  
    20. }
    So, if one wants to add a "fake" delay for testing purposes, and wants to use 2 Cameras where Cam1 follows the Main Camera with x delay and the rendering on Hololens is done from the Cam1. Would this be possible? In Unity Editor is working great but in Hololens no delay happens.
     
    Last edited: May 6, 2020