I have a problem rendering my pixel art sprites properly in Unity. So far I have one character in a sprite-sheet I made, with frames of size 64x64. The actual sprite is roughly 32x32 but I left room for movement in animations. I import the sheet following pixel perfection procedures I found on the internet using these settings:

import settings

As for the orthographic camera I set its size using this formula:

orthoCameraSize = screenHeight / (2 * 32)

If I zoom on the sprite in scene it looks fine but when in game it gets rendered quite poorly (in game / in scene pics below):

enter image description here

What could be the source of the problem? I applied every good practice advice I could find on the web... Thanks for your help!!!!

  • 4
    \$\begingroup\$ An image of the "poor" rendering would help potential answerers helping you out. \$\endgroup\$ – Tyyppi_77 Jul 11 '16 at 22:32
  • \$\begingroup\$ I can double check, but one of my resources said to set the pixels per unit to 100 for 2D images and the camera size to screen height / 2. gamedev.stackexchange.com/a/83437/48257 \$\endgroup\$ – ps2goat Jul 11 '16 at 22:41
  • 1
    \$\begingroup\$ Nothing seems "poor" in the image you showed. The sprites look the same to me. \$\endgroup\$ – Tyyppi_77 Jul 14 '16 at 13:37
  • 3
    \$\begingroup\$ @Tyyppi_77 Zoom in and look more closely at the headband, the row of pixels above the belt and the top of the left boot. The rows are duplicated. \$\endgroup\$ – Philipp Jul 14 '16 at 13:38
  • 1
    \$\begingroup\$ I answered a similar question on StackOverflow - this can be caused when you have a non-integer number of screen pixels for each source texel in the sprite. \$\endgroup\$ – DMGregory Aug 19 '16 at 2:26

You should change your formula for the ortho size to Camera Size = x / ((( x / y ) * 2 ) * s )

Where: x = Screen Width (px) y = Screen Height (px) s = Desired Height of Photoshop Square (px)

  • \$\begingroup\$ I'll have to give this formula a try. I've been doing the screenHeight/2*ppu one I was advised once. Incidentally, how does your formula account for ppu (pixels per unit)? \$\endgroup\$ – jhocking Jul 14 '16 at 14:42
  • \$\begingroup\$ The result from this formula is the same as screenHeight/2*ppu. It's just a slightly more complicated one... \$\endgroup\$ – Uknowho Jul 14 '16 at 14:46

Should be the same problem / answer as this:

How do I move the camera in full pixel intervals?

Basically to fix this issue:

  1. Your sprites-pixel in Unity-Units should be reasonable. ( For example: If your sprite has a width of 10, it should be as wide as "10 unity-units" for example. Or 100. or 1. or 0.1f. But not 1.5234f)
  2. Your sprites should only move in full-pixel-steps if (1.) is not possible.
  3. Your Camera should also only move in a full pixel- steps if (1.) is not possible
  4. Your Resolution should be in full numbers (x = 50.5f is wrong)
  5. Your Resolution should have even numbers
  6. Your Camera-Y-Rotation and Camera-X-Rotation should be 0
  7. Your Camera-Projection should be Orthographic
  8. Your "Size" should be like this : https://indiehoodgames.wordpress.com/2013/07/27/pixel-perfect-calculator-for-orthographic-camera-unity3d/

check the scale slider in game window it must be x1 for better quality

  • 2
    \$\begingroup\$ I think this is a valid answer, but it's a little on the short side and got auto-flagged by our system as a result. I recommend editing your answer to add more details - maybe a link to the documentation about this feature, a screenshot of where to find it & what it looks like in the editor, or an explanation of why scaling using this slider affects visual quality. \$\endgroup\$ – DMGregory Dec 20 '18 at 14:02

Try turning off anti-aliasing completely in the project settings.

Edit -> Project Settings -> Quality

enter image description here

Here, disable Anti Aliasing, and Anisotropic Textures.

  • \$\begingroup\$ thanks Jon. This solution made it a little worse though... \$\endgroup\$ – Uknowho Jul 14 '16 at 13:50
  • 1
    \$\begingroup\$ haha. ok can you provide more details on this particular gameobject? Do you have a 1:1 scale value? Do you have an attached animator? Is the animator affecting the scale of the sprite? Is the actual sprite 32pixels wide? Try setting the camera orthoSize to an integer value. \$\endgroup\$ – jgallant Jul 14 '16 at 13:52
  • \$\begingroup\$ The scale is 1.1, it has an animator which changes the sprite without stretching it, the sprite is actually 32x32. I noticed that if I set the scale to 1 it gets rendered much better, but I have to make it bigger somehow in order to match other sprites size... How can I deal with that...? \$\endgroup\$ – Uknowho Jul 14 '16 at 13:59
  • \$\begingroup\$ You can check out something like this: github.com/RyanNielson/PixelCamera2D -- OR alternatively, another approaches: blogs.unity3d.com/2015/06/19/pixel-perfect-2d \$\endgroup\$ – jgallant Jul 14 '16 at 14:02

Try setting the compression to rgba 24bit (override default) and filter mode to point.

  • \$\begingroup\$ You can see in the question itself that the texture has already been imported uncompressed, with point filtering - so this isn't telling the user anything they haven't already done. Plus, the artifacts shown don't look like compression or bilinear interpolation, so it's unclear how this answer is intended to solve the problem. \$\endgroup\$ – DMGregory Mar 27 '17 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.