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. Dismiss Notice

Is it possible to render a camera's view within the world and have it rendered by another camera?

Discussion in 'Editor & General Support' started by JeffersonTD, Oct 1, 2014.

  1. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    267
    I have a game with 1 main camera and 5 simple single-purpose cameras. What I would like to do is have the views of the 5 simple cameras rendered within the world and shown through the main camera. Is this technically possible?
     
  2. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Yes. Render to render textures.
     
    JeffersonTD likes this.
  3. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    267
    Ah, right. Thanks! It's a pity, it's a Pro feature though.
     
  4. Valette

    Valette

    Joined:
    Jun 9, 2014
    Posts:
    68
    Not necessarily what you're after (and this would probably involve a huge performance hit if you did it every frame) but I've rendered cameras inside other cameras using Unity Free by doing something like this. Probably not great for a real time view but useful if you need screenshots inside the game.

    Code (CSharp):
    1. void OnPostRender()
    2.     {
    3.     Texture2D tex;
    4.     tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
    5.      tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    6.       tex.Apply();
    7. }
     
  5. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    267
    Thanks for the idea. I had actually already been considering doing a thing like this, but I was also concerned that it might affect performance too much so as my need to support different angles for viewing the camera views is limited I decided to just calculate the correct position where to render the camera views to sort of fake it into the world. Seems to be working almost as nicely as actually having it inside the world.