Search Unity

Question About Multiple Cameras

Discussion in 'Scripting' started by CgRobot, Dec 19, 2011.

  1. CgRobot

    CgRobot

    Joined:
    Jan 4, 2011
    Posts:
    175
    Hey everyone. There is a project of mine that would benefit from having a split screen for multiple players. I know how to split the screen but it does not do it the way I want it done for my project. The way the screen is split right now is one camera will compress everything that would normally be viewed in full screen and puts it into the defined amount of space. This effect is usually what is needed, but for what I want I can't have the view become smaller. Instead, what I am looking for is a way to have both cameras in the same position and rendering the view port in full screen, and them mask half of one camera's view port. That way, both views stay undistorted and the same size. How would I do this?

    If anyone has seen or played the game Lego Pirates of the Caribbean, their split screen effect is very similar to what I am trying to achieve, although theirs is fancier than what I need.
     
  2. CgRobot

    CgRobot

    Joined:
    Jan 4, 2011
    Posts:
    175
    Anyone? If my problem is unclear, let me know so I can fix it.
     
  3. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    To get that effect you'd need to understand projection matrices. Well, maybe, I'm just guessing (been ages since I played those games, not even sure if I'm rembering this correctly) but I think the way you'd do that is to use a custom projection matrix for each camera that when both players are on screen in looks for all intents and purposes as if it were a single camera. As the players move towards the edges of the screen it begins to interpolate each modified projection towards a more standard one, as the charters come back together the two projection matrices smoothly sync back up again. There's probably some switching between a single/dual camera in there somewhere too for performance reasons, but that's the crux of it I reckon.

    Or you could just create three cameras and hot-switch them directly and not care about the perspective jump when character get towards the edge of the screen.
     
    Last edited: Dec 20, 2011
  4. apple_motion

    apple_motion

    Joined:
    Jul 2, 2009
    Posts:
    169
    Well, you should post a screen capture for us, otherwise we really don't know what you really want :p

    Anyway, did you means the split screen like the attached one ? Seems like it made by a mask on an overlay camera.
     

    Attached Files:

  5. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Oh, that's what he meant.

    Yes, picture = 1000 words.
     
  6. CgRobot

    CgRobot

    Joined:
    Jan 4, 2011
    Posts:
    175
    That seems a little bit more involved than then what I was hoping for. If that is the only way I may try to figure out how to do that.

    @apple_motion
    That's exactly what I was talking about. Although I don't need the split to rotate like theirs does.
     
  7. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Edit: Might be able to do something similar just by rotating cameras a little like so:



    That is two cameras in exact same location setup as you usually would a split screen, left camera has blue background rotated 25 degrees left. Right camera has black background rotated 25 degrees right - screen ratio 16:10 with camera FOV 60. There's a bit of overlap but it's close.

    Only problem is, FOV in unity is based on screen height not screen width so to make it prefect and seamless if both players in same relative location you'll need to do the height/width ratio adjustments. Script cameras track each player then clamp to minimum angle between them or something.
     
    Last edited: Dec 20, 2011
  8. CgRobot

    CgRobot

    Joined:
    Jan 4, 2011
    Posts:
    175
    Ok. I understand everything you are doing, but are you normalizing the view-port at all when you do this? If not, how do you get both cameras to render at the same time? Is it a Unity Pro only ability (I noticed you have the Pro version)? I only have the Indie version. Also, when I tried this with the view-port normalized, it didn't overlap, but there was a lot of perspective distortion an it didn't look good at all. The cameras are rotated 30 degrees instead of 25.

    $Split Screen Problem.jpg

    Now if the perspective can be corrected, it would look great.
     
    Last edited: Dec 20, 2011
  9. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    This dynamic rotating LEGO Split screen is exactly what i am looking to achieve,
    Can you point me to the right keywords to search?

    So basically i create 2 overlapping cameras and attach a certain overlay mask...
     
  10. CgRobot

    CgRobot

    Joined:
    Jan 4, 2011
    Posts:
    175
    Actually, I still have not been able to get the correct effect like in the Lego game. If there was a way to mask part of what one camera saw and placed that onto another camera then that should work. Only a little bit of scripting would then be needed to get the movement to work the way you desire it. I do not know of any way to do this however. If you continue your searching and you find a way to do this, I would appreciate it very much if you post your solution here.
     
  11. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    Ive found smth:

    http://www.youtube.com/watch?v=XzIzHKwVDH4

    He has a link to a tutorial which shows how to mask things in the description. he said hell make a tut of the splitscreen thing too sometime soon...