Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

HDRP and multiple cameras (main + UI)

Discussion in 'High Definition Render Pipeline' started by mherbold, Feb 27, 2021.

  1. mherbold

    mherbold

    Joined:
    Jun 4, 2017
    Posts:
    35
    I have an HDRP scene where I am using a main camera for 3D and another camera for UI (canvas).

    For the main camera, I am trying to adjust the camera's viewport to fit within a certain square on the screen.

    The problem is, whenever the UI camera is enabled, the main camera's viewport X and Y are stuck at whatever the UI camera's viewport's X and Y are set to. The main camera's viewport width and height still works as intended. This means while I can resize the main camera's viewport, I cannot change the placement of the viewport on the screen, while the UI camera is enabled. When the UI camera is disabled, the X/Y/W/H of the main camera's viewport all works.

    To reiterate - it is ONLY the X and Y of the main camera's viewport that becomes "stuck" to the UI camera's X and Y viewport coordinates. If I change the UI camera's X and Y viewport coordinates, it magically moves the main camera's viewport around on screen, which is not what is supposed to happen.

    Please fix this!
     
  2. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    I hate to sound like a broken record, but HDRP does NOT like/support more than 1 camera. Unless you want to use Compositor, and that includes UI. Best choice is wait a bit for the new HDRP UI Shaders to be released...
     
    xVergilx likes this.
  3. mherbold

    mherbold

    Joined:
    Jun 4, 2017
    Posts:
    35
    I refactored my code so that instead of two cameras (the main scene camera and the UI camera) trying to render to the same frame buffer, I changed my main camera to render to a render target, and the added the RT texture as a RawImage child of the Canvas and it works perfectly in HDRP. I also changed the UI camera to clear to a color instead of not clearing. I still have the same two cameras, and changing them this way actually fixed a few other artifacts that I was seeing (relating to reflection probes and global volumes). So I would say that HDRP can do multiple cameras, just not on the same frame buffer.
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Cost of multi-camera setup is absurd.
    So even if you've found out a workaround, its better to avoid multi-camera setup all around.
     
    warthos3399 likes this.
  5. mherbold

    mherbold

    Joined:
    Jun 4, 2017
    Posts:
    35
    A multi-camera setup is the only way to achieve things like rear view / side view mirrors. Avoiding multi-camera is simply not an option in my case as I need a non-centered main view (like Bard's Tale).
     
  6. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    Feel for ya, but we will have it soon, just not soon enough, lol