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

Question Letterbox Bar Graphics

Discussion in 'Scripting' started by Sylon87, Oct 7, 2020.

  1. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196
    hello!
    Out of the box, the letterbox / pillarbox bars will just be the default colour of the framebuffer (generally cleared to black). i want fill these areas with graphics, anyone know how?
     
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,528
    I'm not sure what you are asking. AFAIK Unity does not letterbox or pillarbox the camera automatically. Or do you talk about the preview in the game view when you set a certain aspect ratio / screen resolution? This editor feature is meant to show you how your game will look like on such an aspect ratio / a screen resolution. If you want to deliberately add letterboxing / pillarboxing to your game you would have to do this through a script.

    If it's just about the UI you can use a CanvasScaler like explained over here. If you're interested in a solution for a camera, see this answer over here.
     
  3. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196

    i did exactly that, and i can't figure out how to do this
    'Out of the box, the letterbox / pillarbox bars will just be the default colour of the framebuffer (generally cleared to black). You can fill these areas with graphics using a screenspace overlay canvas or additional cameras.'

    thank's you for your help
     
  4. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196

    Attached Files:

    Last edited: Oct 7, 2020
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,528
    Well, like it's explained in the second link I've posted you can simply use two cameras. One that renders to the whole screen (filling the pillarbox / letterbox area) and a second camera which is your actual camera rendering on top. Just set the depth of the cameras accordingly.
     
  6. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196
    thank's you for your help, because i don't want to create another camera i just wondering to how do this "using a screenspace overlay canvas" i already have a screenspace overlay canvas but i can't figure out to how to do it...
     
  7. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,528
    And what's the reason for this decision? Setting up a seperate camera is way easier to configure and to ensure the rendering order is correct. Using a screenspace Canvas and a render texture does work. However you would also need a seperate camera to clear the background. If you let your actual scene camera render into a texture, nothing will be shown on the screen. You would present the actual rendertexture with a rawtexture component in the Canvas. You can place the rawtexture as you want inside your canvas and also add your desired background image in the canvas. So your actual screen would only contain a Canvas with two images: your background image and the raw image showing the rendertexture of your camera. However doing this you would have no camera actually rendering to the screen. The Unity editor shows a warning overlay (which is really annoying) that there's no camera rendering to the screen. Though when the canvas is filling the whole screen this shouldn't matter at runtime. However to get rid of the warning you would need a seperate camera that takes care of clearing the screen.

    Keep in mind if you use letterboxing or pillarboxing your screen resolution / screen space does not match your camera view area. So you have to be careful with mouse or touch events. Though this is an entire seperate story ^^.
     
    Xarbrough likes this.
  8. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196

    thank's you for your help!
    since my game doesn't use mouse or touch input it should be fine, but i'm just worried about the performance side due to use a second camera to render the graphics, but if it's the only way.. i would give it a try..
     
  9. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,528
    A camera does not really add any kind of performance overhead by itself. It just depends on what it actually renders. In terms of fillrate, yes you get some overdraw. If you worried about this you could simply use 3 cameras and arrange them without overlap. So the main camera in the center and one camera for each letterbox / pillarbox "strip". That way you avoid unnecessary overdraw. Of course it's also possible to manually draw a custom mesh with the two strips in one draw call in some post processing callback. Though I doubt that this will gain you anything. Keep in mind that any postprocessing effect you may be using is essentially a screenspace quad rendered on top of your scene and adds to your fillrate. Even mobile devices nowadays shouldn't have that much of an issue with this.

    Though the only real answer to your concerns are: profile, profile, profile :)
     
  10. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    I'm confused about why there's so much discussion of using a second camera for this. Sorry if I've missed something here, but I use a letterbox feature, which is just a plain old canvas containing a pair of black-tinted images that go at the top and bottom of the screen. No need for an extra camera. Is there some reason why using a canvas and images like this won't work for you?
     
  11. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196

    Because i need it only visible on aspect ratio different from full screen that would be 1920x1080,