- Home /
Graphics.Blit scale
Hey,
Just learning about Blit and wondering if it's possible to scale it so that it doesn't stretch to fill the whole screen and stay at a fixed aspect ratio instead?
My game is rendered to a low res rendertexture and then blitted to screen, but i want it to stay 16:9 regardless of screen resolution.
Thanks
Answer by Bunny83 · Jan 19, 2018 at 06:40 PM
In short: No. Graphics.Blit will always draw a fullscreen rectangle. So it will always fill the entire screen / area of the destination. RenderTexture.
However you can scale the incoming texture by using the scale parameter. So you can render a part of the source texture to the full destination texture.
Thanks, could you provide a simple example of how to scale the inco$$anonymous$$g texture?
I think i deleted one of my comments at the same time you posted a reply, here's what you wrote:
Well, i haven't really used Blit that much. However to get the same result you currently get you have to pass a scale of (1, 1) and an offset of (0, 0). I'm not sure in which order the scale and offset are applied but usually the scale is applied first and the offset is added afterwards. I also don't know where the origin is located, but since we talk about UV coordinates 0,0 should be the bottom left, and 1, 1 should be the top right corner. In theory if you have a square source image and you want to cut the top and bottom to get a 16:9 ratio you would do something like: scale = new Vector2(1f, 9f/16f); offset = new Vector2(0f, -(1f-9f/16f) 0.5f) This is pure speculative. $$anonymous$$aybe the offset need to be positive, if the origin is the screen center the offset need to be 0, 0*
I messed around with the scaling and offset and the issue is that it stretches the borders to fill the empty space which doesn't look good, I played around with the camera's viewport rect settings ins$$anonymous$$d and it does the same thing and has nice black bars, I just need to figure out the equation and that should work.
Thanks!
For some reason Unity Answers is ignoring paragraphs and clumping everything together, i'm sorry about the mess.