Search Unity

Dual camera rendering and virtual camera question.

Discussion in 'Cinemachine' started by r_carter, Jan 8, 2019.

  1. r_carter

    r_carter

    Joined:
    Apr 4, 2013
    Posts:
    8
    I have two cameras render different layers.
    One with Don't Clear option, so the geometry is sorted correctly.
    As you can see, at the top image the plane cuts the sphere.
    But when I add a virtual camera, the objects are simply shown in the order of camera depth.
    What am I doing wrong?

     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    All the vcam does is to set the position, rotation, and FOV/near/far of the camera. This happens in the CMBrain's LateUpdate. It does not affect the culling. It looks as though the main camera is rendering after the additional camera, when what you want is the opposite. You need to find a way to ensure correct rendering order of your cameras.
     
  3. r_carter

    r_carter

    Joined:
    Apr 4, 2013
    Posts:
    8
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    I don't know why that's happening. Does it happen also in play mode?

    In any case, having 2 cameras is potentially going to make trouble, as CM will be driving the parent camera only, but for your compositing to work, the child camera will need identical lens settings. You might need to add some code to enforce that. If you do, make sure that the script execution order is such that your script updates after CinemachineBrain, or that it hooks into the Brain's OnCameraUpdated event.
     
  5. r_carter

    r_carter

    Joined:
    Apr 4, 2013
    Posts:
    8
    Yes, also in play mode. And on other scenes. And it's not about the camera lenses, they're the same.
    Two other strange effects after removing the brain and virtual camera from the scene
    1) nothing changes in game view, it continues to render primitives without culling, not as before, with only two common cameras.
    2) additional camera preview in the editior starts to show the plane, despite that plane lays on the default layer, while the camera must render only grid layer.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    I doubt CM has anything to do with it, honestly. CM doesn't mess with any culling.
    Since the rendering order of the cameras matters, I can ask: what are you doing to create a deterministic rendering order?
     
  7. r_carter

    r_carter

    Joined:
    Apr 4, 2013
    Posts:
    8
    Should I? Before adding the CM, the depth of the cameras was enough.
    If the CM doesn't change anything should not be required after.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    If you would like to send me a simple project that demonstrates this I can have a look at it.