Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Splitscreen to RenderTexture

Discussion in 'General Graphics' started by yuzu_drink, Jun 8, 2015.

  1. yuzu_drink

    yuzu_drink

    Joined:
    Jan 15, 2012
    Posts:
    14
    I'm trying to set up a view where I have two cameras rendering to different parts of a RenderTexture. However, when I attach a RenderTexture to each camera, it seems that its Viewport Rect gets ignored.

    Am I missing something? Is there any decent workaround for this?

    Thanks!
     
  2. ThomasCreate

    ThomasCreate

    Joined:
    Feb 23, 2015
    Posts:
    81
    This behavior is intended:

    Either don't have the cameras render to a render texture but to the screen directly, or if you really need them to render to a texture first, you have to manually create the split screen. Have each of the cameras render to a texture with half the screen height, then use Graphics.DrawTexture() to draw those render textures onto a third one, at their respective positions. A good place to do this would be in a script that's attached to a camera that outputs the combined texture to the screen. Override OnRenderImage(), and blit the combined texture onto the "dest" render texture in that method.
     
  3. mholub

    mholub

    Joined:
    Oct 3, 2012
    Posts:
    123
    I've just tried and viewport setting works with RenderTexture for me.
    Can you try my attached example?
     

    Attached Files:

  4. ThomasCreate

    ThomasCreate

    Joined:
    Feb 23, 2015
    Posts:
    81
    Well I'll be, looks like it does work. I could've sworn I've tried it before and failed - I guess the documentation needs some updating then.
     
  5. QuinnWinters

    QuinnWinters

    Joined:
    Dec 31, 2013
    Posts:
    490
    Sorry to necro an old thread but since this is the top result on google for sending split screen to a render texture this info needs to be in it. This will not work if you have HDR checked on your cameras. High dynamic range and sending custom viewport rects to render textures do not work together for some reason. It took me hours of frustration before I finally realized that was why I couldn't get it to work like mholub's example.
     
    Gavinsta likes this.