Search Issue Tracker
By Design
Votes
2
Found in
2018.4
2019.4
2019.4.9f1
2020.1
2020.2
Issue ID
1275228
Regression
No
Sprite is offset and distorted when using the Sprite Renderer Flip option for X-axis and Game view resolution is set to 480x270
How to reproduce:
1. Open the attached project named "Case_1275228"
2. Open the SampleScene
3. Switch to Game view and check if the selected resolution is 480x270(Zoom in for better sprite visibility)
4. Select the TestSprite in the Hierarchy view
5. In the Inspector window check Flip for X-axis under the Sprite Renderer settings
Expected result: The sprite is flipped by its X-axis and it is not distorted or offset
Actual result: The flipped sprite becomes offset to the right and distorted
Reproducible with: 2018.4.27f1, 2019.4.11f1, 2020.1.6f1, 2020.2.0b3
Workaround - Copying the sprite and flipping it using a 3rd party foto editing tool. A simple script can then be used to switch between two sprites in order to flip them
Notes:
1. It appears that only 480x270 is affected. Also tested these resolutions which worked fine - 320x180, 384x216, 960x540, 720x480, 720x576, 1280x720, 1920x1080, 3840x2160
-
CoolJosh3k
Sep 15, 2020 00:40
If set to the correct camera values for a 720p, pixel perfect resolution this issue can be reproduced again. This time with a camera x position of 0.29688.
Here is some code which, when run, will adjust to the nearest exact pixel perfect camera values for the base resolution of 480x270. Just run via a update loop, button, or whatever, while the player (or game tab) is set to 1280x720.
You can use free aspect to get any valid resolution output, but I have yet to observe this at any resolution other than (pixel perfect) 480p and (pixel perfect) 720p.const int BASE_RESOLUTION_X = 480;
const int BASE_RESOLUTION_Y = 270;
const float BASE_ASPECT_RATIO = (float)BASE_RESOLUTION_X / BASE_RESOLUTION_Y;
void AdjustCamera() {
Camera.main.aspect = BASE_ASPECT_RATIO;
Rect rect = new Rect(0f, 0f, 1f, 1f);
//Clear the screen
Camera.main.rect = rect;
GL.Clear(false, true, Color.black);
//Calculate the zoom as a floored value
int zoomX = Screen.width / BASE_RESOLUTION_X;
int zoomY = Screen.height / BASE_RESOLUTION_Y;
int zoom = Mathf.Max(1, Mathf.Min(zoomY, zoomX));
//Create the pixelRect
rect.width = zoom * BASE_RESOLUTION_X;
rect.height = zoom * BASE_RESOLUTION_Y;
rect.x = (Screen.width - (int)rect.width) / 2;
rect.y = (Screen.height - (int)rect.height) / 2;
//Set the pixelRect
Camera.main.pixelRect = rect;
}The camera's x position must be changed to 0.29688 to observe the bug at 720p.
-
CoolJosh3k
Sep 11, 2020 21:33
Another workaround to fix this issue is to set the orthographic size to integer multiple, such as 4x (from 8.4375 to 33.75) and then scale every single game object to the same 4x.
This will have no visual size difference, but will prevent the rendering bug from occuring.
This is handy alternative, since this does not require messing about with extra sprites.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Incorrect ScrollToItem behavior when called on a deattached ListView
- Zooming in/out in Scene View window on the display the zoom takes place in does not work
- Changing Game View resolution when there are 2 Game View Windows on 2 different displays makes the view stretched
- Maximising Game view window on one display makes black bars appear on another display
- Creating a 3D Object when using 2 monitors and 2 Game View Windows on different monitors the created 3D Object only appears on one of them
Resolution Note:
This is an inherent issue of nearest-point sampling. See a detailed explanation here: https://docs.microsoft.com/en-us/windows/win32/direct3d9/nearest-point-sampling
Flipping the sprites will cause the UV calculation to change slightly, and possibly cause your scene to sample the texture at texel boundaries. The solution is to use the Pixel Perfect Camera, which internally adjusts the position of both the camera and the sprites to avoid sampling at texel boundaries.