How do I make Pixel Perfect Camera scale like Normal Camera in Unity 2D - unity3d

This is my scene
Right now if I use resolutions that aren't 16:9 the Pixel Perfect Camera zooms out quite a lot showing parts that shouldn't be shown.
How do I get it to scale like the Normal Camera which just cuts out parts outside the borders?
The Reference Resolution is currently set to 320x180, I tried changing the Reference Resolution to other resolutions (640x360, etc) but that changed nothing.
Tried Pixel Snapping on/off.
Cropping the X and Y does a good job at hiding the outside borders places but makes the screen too small for non 16:9 resolutions.

Related

Unity on mobile cuts off sides (not canvas related), on different resolutions

I'm developing a 3d game on unity and using the 1080x1920 portrait resolution.
When I build and run the project on my phone, which has a 1080x2340 resolution in portrait, it cuts off part of the game (the sides).
red lines indicating where it cuts off
The camera doesn't follow, so the player can "go out of the screen".
How can I fix this, making sure my game looks the same on different resolutions?
(edited to correct resolution order)
Does your play area have a fixed size? If the in-game play area's aspect ratio isn't the same as the device running the game, you'll have to either cut off part of it or include blank space at the top/bottom or left/right. Unity's camera orthographic size dictates how tall the camera view is, but not how wide. The width is just screenAspectRatio * camera orthographic size.
To fix this:
float aspect = Screen.Width / Screen.Height;
myCamera.orthographicSize = Mathf.Max(playAreaHeight, playAreaWidth / aspect);
This will cause the camera's view to be either too wide or too tall rather than too small.

Physical Camera Viewport should adjust with the UI for different resolution

I have a physical camera in the scene which renders a 3D Scene. The 3D Scene is rendered between the Top UI Bar and the Bottom UI Bar and has been set properly for reference resolution 720 x 1280.
So, the problem is when the resolution changes, the UI is set properly for that particular resolution. But the 3D scene that is rendered between the 2 UI parts, doesn't sit properly between them. I am attaching 2 reference images for easier understanding.
The below-given image is based on the reference resolution and the 3D Scene is properly fit between the 2 UI parts.
The below-given image is for another resolution where the UI adjusts itself accordingly. But the 3D scene doesn't, i.e the camera should move to fit the 3D Scene between the UI.
So, is there any way I can move the camera according to the resolution so that it fits properly between the UI for different aspect ratios.
Thank you.
First of all, try looking at the ViewportRect property of the camera - it enables you to crop the viewport to an area which should enable the effect you seek.
This however has the limitation of keeping the 'center scren' axis of perspective, which in some cases is uncalled for.
An 'should always work' solution is rendering to a RednerTexture - camera adapts its screen aspect to the aspect of the RenderTexture, and if you display your texture on RawImage, you should get dececnt results. This however has some performance cost (memory readout is not the fastest on mobile).
In case the cost woul be unnaceptable, its possible to construct custom camera projection matrix, that would respect your desired viewport rect, and also allow arbitrary perspective, but its not trivial unfrotunately. Here is some more information
https://docs.unity3d.com/ScriptReference/Camera-projectionMatrix.html

Why is my pixel art scaling wrong on other resolutions?

My pixel art assets all have a ppu of 32 and i have applied that to them all.
On 1920x1080, the resolution is fine, but most other resolutions the sprites pixels are squashed and stretched. I also have set the correct camera size using vertical resolution / PPU / 2). I have also used other formulas and they all give me the same camera size so i'm sure that's not the issue.
I have two moniters, one at 1920x1080, and one at 1360x768, and that moniter is where it scales wrong. Is there a way i can keep the pixels scaling the same across all resolutions? I have tried the pixel perfect camera and this doesn't fix my issue either.
https://imgur.com/gallery/Uf8YqNi Here is a sample of both resolutions, if you open them in a new tab and zoom in on the sprite you can see how tey get distorted in the 1360x768 screen.
Filter mode should be Point and compression None. If this doesn't fix it, then you should use Pixel Perfect camera. It will help you with the animations to be pixel perfect as well.
Window -> Package Manager -> Advanced -> Show preview packages -> 2D Pixel Perfect -> Instlal. Then you just add Pixel Perfect Camera component to your Camera.

Image size incorrect in Unity

I have a Unity 2D project with a fixed screen size of 800x450 pixels.
I have imported a background image that is also 800x450 pixels.
When placed on the stage, the image only takes up half of the screen.
The scale of the image is set to 1,1. The Z position is 0.
Why is the image displayed too small? How can I display the image at the correct resolution?
Does this mean that I have to design all my game assets at 2x the required size? Or that I somehow have to set the scale for all imported assets at 2? What is the recommended workflow?
EDIT
I have added a screenshot of the camera settings:
I would trying making your camera orthographic, and set the size of the camera (not the transform) to be half the height that you would like it to be (225)
Also if you are looking for pixel perfect game. here is a pretty good article from Unity about how to make that work and it explains some of the camera aspect ratios and scaling
http://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/

OpenGL ES : getting a fixed size for an object

I have an open GL ES (1.1) scene with many 3d objects and a "player" model. I'd like the player to have the same pixel size, regardless of the screen orientation on an Android phone or Iphone.
I'm not using glOrtho or billboards. That's a perspective 3d scene, but I just want the objects to have the same size in both screen orientation. Currently, if I rotate the phone, I keep the same aspect ratio but the scene "zooms out" in landscape mode.
I suspect that I have to play with parameters to glFrustrum to get this; but can't figure out yet how to do it.
So any ideas are welcome!
Thanks
You will need to change the aspect ratio when the device is turned to go from a the otherwise the size of the objects are going to change. THink of yourself looking out through a window, the objects on the other side of the window are only going to be the same size if you don't change your distance from the window (i.e. zooom in and out), when you "turn" the window sidewayse, the aspect ratio of the window changes (the metaphor is starting to not work).
If you draw a square in the view with the side length being the short side of the screen, then you should still have a square when you turn the phone sideways, still covering the same area on the screen.
Things will probably be easier to calculate if you use the code from gluPerspective. You set the aspect ratio to the actual aspect ratio, fix the fovy for the first aspect ratio. You can then use what would be fovx for this aspect ratio as the fovy for your rotated view.