1
\$\begingroup\$

So I've been studying the Unity's PPU, pixel density, camera settings topic to make my game pixel-perfect. I've set everything in a way that my screen pixel to sprite texel ratio equals 1.

The art looks very good and crisp overall on the game view...

But!

There are still some minor distortions and I don't know where it comes from.

Take a look at this example:

enter image description here

In this example my settings are:

  • Screen: 870x510
  • PPU: 100
  • Camera size: 2.55
  • Pixel snap on Sprite material: on

The issue happens when I move the sprite manually by ~0.001 values on the Y axis. Same happens on the X axis.

Any ideas what's the problem?

\$\endgroup\$
  • 2
    \$\begingroup\$ 2.55 and 100 aren't powers of 2, so it's possible you're experiencing some rounding in the math when performed in binary. What happens if you make your PPU 128, for example? (Adjusting your positions & camera accordingly) \$\endgroup\$ – DMGregory May 3 '18 at 15:25
  • \$\begingroup\$ In fact, why 0.001 values? This would be correct behavior if your grid were along pixel boundaries or straddling the midpoints between pixels, depending on your sampling algorithm (it appears to be 'nearest'.) I would try to consider what your screen would be doing with a 2x2 resolution to rule out initial alignment. I have no experience with Unity, so I apologize if I have a poor grasp of the problem (but it sounds like one I've had in rendering, image editing, etc.) \$\endgroup\$ – John P May 3 '18 at 15:46
  • \$\begingroup\$ @DMGregory Well, the problem did disappear. What's interesting is that when I used something like a 1675/946 res with 118 PPU and 4.008474 orto (I'm messing around in Free Aspect mode) the problem also doesn't exist, so is it really a problem of numbers not being powers of 2? \$\endgroup\$ – sarneeh May 3 '18 at 15:50
  • \$\begingroup\$ I wouldn't be satisfied with that... if it was due to a change in rounding, it would probably still exist until you determined and fixed the original cause. Check this guide for comments on these settings: twitter.com/davitsu/status/956499799133573120 -> filtering off, ortho size coupled with PPU, and what I suspect to be an issue, 'snap to grid' should be on for sprites of this size. Powers of two should not be a problem; 2.55 actually makes sense to me - (2^8-1)/100 - although I would be curious to see what 2.56 did. Your ortho didn't make sense to me, sorry, was it arbitrary? \$\endgroup\$ – John P May 3 '18 at 15:59
  • \$\begingroup\$ @JohnP Camera Ortho Size (2.55) = Screen Height (510) divided by PPU (100) divided by 2 (since it's a half-extent) \$\endgroup\$ – DMGregory May 3 '18 at 16:01
1
\$\begingroup\$

So the problem was that there was some kind of artifact going on caused by how the sprite meshes were constructed.

When i changed the mesh type of the sprite to rect - the problem disappeared. Here's a comparison of a sprite with mesh type tight (left) and rect (right):

enter image description here

Here's how the sprites were mapped to meshes in Unity:

enter image description here

\$\endgroup\$

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.