Help fixing a major flaw in Unity2D.

No matter what I try, it seems there is no solution.

I have a simple 2D map, which just has some sprites on it. These sprites refuse to render correctly, resulting in everything from flickering, line warping, to simple pixel distortion. Each failed “solution” causes a different effect. The best I can get, still results in pixel distortion. Here is exactly the problem:

1614181--98272--$Unity-pixel-distortion.gif

^ This is the best solution. Other “solutions” display far worse rendering.
Even with this, when pixel perfect, everything shakes violent upon moving. I have to be x2 zoomed in (4x4 per pixel) for it to not shake and render seemingly well.

Obviously without POINT filtering, it renders perfectly. However, one cannot make a pixel art game with such incredible blur.

I have tried all known solutions to this.

Pixel Snap (Makes the problem worse in every situation)
Pixel Perfect Camera scripts (Is required to get a stable image some/most of hte time, but still not always stable pixels.)
Unity Pro Feature - Mesh Type: Full Rect (Does absolutely nothing.)
Y Offset of 0.001 (Fixes the problem when camera is at Location1, but the problem persists in a different Location2. Not a real solution.
POT textures Fixes pixel distortion caused by NPOT textures, but does not fix pixel distortion caused by Unity’s rendering.
Point Filtering Required to not get blurry sprites. Required for pixel perfect rendering.
TrueColor Required.
Pixels Per Unit @ 1

Is this a bug Unity is aware of?
It’s pretty bad to call yourself a 2D engine (as of 4.3) and still have such a major rendering flaw, that you cannot even render pixels correctly.

1 Like

What about turning off Anti-Aliasing? Edit > Project Settings > Quality. Under rendering.

No Anti-Aliasing is enabled.

Pixel Light Count: 1
Texture Quality: Full Res
Anisotrophic Textures: Disabled
Anti-Aliasing: Disabled
Soft Particles: unchecked

This happens in both Editor running the game.

Tried all the different settings.

As much of a PoS PITA it was, I restructured all of my code to make Pixels Per Unit 100, instead of 1.
There is absolutely no difference.

This is just how point filtering works… It’s not a Unity-specific issue. Back in the old days, sprites used to move by pixels, so you wouldn’t see this distortion happening, but as the hardware got better, bilinear filtering was invented to combat the exact issue you’re talking about. You’re asking for sub-pixel screen-movement, while using a filtering type that says to not use sub-pixel filtering. That does not compute.

Your options are:
1.) Only allow the camera’s movements to move a pixel or multiple pixels at a time, but never a fraction of a pixel.

2.) Scale up your sprites in Photoshop or w/e, using “Nearest Neighbor” or “Point Filtering”, and save them out and use Bilinear Filtering in Unity instead. This way your sprites will be sharp enough, but they will also be able to blend between pixels.

2 Likes

Thank you for the advice. This sounds like it has a good chance to work.

I will post any updates.

Point 1x1 (Pixel = 1x1 - Original Default)
This is the default, with problem.

Point 4x4 (Pixel = 4x4, so the texture is 400% enlarged.)
Camera: Zoomed out x4. I set the Camera’s script’s PixelsPerUnit variable from 200 to 50 ( PixelsPerUnit / 4 to compensate for the 400% enlarged texture)
This looks identical to the default Point 1x1, but the problem is significantly better. Different pixel distortion occurs, but it looks less worse, and is less common, less noticeable.

edit: Completely unacceptable. This distorts pixels even worse at some resolutions.

Trillinear 1x1
This is so blurry, it is unacceptable.

Trillinear 4x4 (400% enlarged texture AND Billinear filtering instead of Point)

This looks pretty close to the original. It is still altered quite a bit- but it’s actually still pixel art - looking like it uses half-pixels at the top.
You can tell there is a slight blur visually when zoomed out, BUT it is not very noticeable. Some gamers would never notice the difference between Trillinear 4x4 and Point filtering.

edit: Most acceptable version. This still has some shaking problems though, at least in my Scene. Not entirely sure if shaking issues would occur with other people’s scenes (Might be my combination with Vectrosity).

My testing was inconclusive because I did not spend enough time on it (and would need to change a good amount of code in some classes functions) BUT it did seem to resolve the issue for the most part.

It is so silly, but if you take a 40x40 texture and shrink it via the Camera size being / 4, it renders closer to pixel perfect than 1:1 pixel perfect would.

I’d call this idiocy, “4:4 pixel perfect”.

It is still entirely Unity’s fault renderer, which is more competent when shrinking larger textures than display accurate pixels. Of course, this makes sense because otherwise Unity would have the same problem in 3D rendering with tons of 3D flickering.

This is Unity’s fault, because this is not the case in any other renderer, game engine, or game framework. This is a Unity exclusive fault, not the fault of Point filtering or Texture size. I have used several engines (mostly 2D) which are much more seamless but have the same functionality (such as using float points for player movement). Unity is obviously very good at displaying larger textures in smaller pixel areas, and very bad at displaying exact pixels at exact areas.

Obviously Unity IS capable of the same functionality of other 2D renderers, but you have to handle it with 3D methods (shrinking larger textures results in more accurate pixel rendering than rendering smaller pixels in the exact same location). Take note, that it isn’t because Unity is actually rendering larger textures. The camera adjustment results in Unity rendering the exact same number of pixels as 1:1 pixel perfect would. It simply chooses the correct location for each pixel with more precision.

Of course, Bilinear filtering mode does make it even smoother than Point 4x4, although both are very acceptable solutions. At least from what I noticed when spending a few minutes moving the player around in my scene. It is hard to say if this is a definite solution, or simply the best one so far.

1 Like

Next, I will be rendering the same pixels using Color[ ] arrays and Vectrosity.

Vectrosity seems fully capable of rendering pixels 1:1, with absolute accuracy.

In the end, I might simply completely discard Sprites and simply use Vectrosity to render EVERYTHING.

The pixels in Vectrosity seem to be precise and never flick or change, no matter where the camera or player moves to.

This problem is exclusive to Sprites and 4.3 functionality. So far, anyway. I will conclude with Vectrosity’s success after I implement it.

I used Vectrosity to render everything, eliminating the Sprites entirely.

Absolutely Perfect.

Pixel Perfect.
No flicker. No twitching. No distorted pixels.

Abso. Lutely. Perfect.

Thanks Vectrosity!!!

┌∩┐(◣_◢)┌∩┐ Unity2D!

I cannot thank Eric5h5 enough.

Zoomed in, it is even more flawless. So smooth. So perfect. So fulfilling of my perfectionist requirement to not have ANY pixels distort. drools

Zoomed out? Absolutely no shaking. No twitching. No problem.

I even get better scrolling performance!

I cannot express how flawless it is now. Before it didn’t just distort, it also shook the objects, the screen had mini-seizures, weird scanlines warped over it sometimes, etc.
It was partially acceptable only at x2 camera zoom, with distortion of pixels and tiny shaking at BEST.

With Vectrosity, absolutely flawless in all zoom levels (1:1, 2:1, 4:1, etc.)
If I tried zooming out to 1:1 (true pixel perfect rendering) using Unity Sprites, it would shake everything violently (violently enough to make me scream like lemongrab “UNACCEPTABLE!!!”.) With Vectrosity it is so smooth.

Unity2d…

1 Like

Of course, if you’re using a purely shader/code method that’s using anti-aliasing as well, like Vectrosity does, it’s going to avoid the issue -_-. The shader is generating an image for the given area of pixels it is appearing on, it is completely different from a texture/sprite, where the information is static. Recreate this demo in GameMaker for example, the same thing would happen. Perhaps a few engines use sub-pixel rendering to get around this issue, but most don’t, since it incurs a larger performance cost. You could probably modify the Sprite Shader to do sub-pixel rendering to avoid this issue.

Even textures on a 3D plane will have this issue.
Here’s a post detailing the issue, not related to Unity at all.
http://stackoverflow.com/questions/14246604/2d-texture-gets-distorted-when-making-a-sub-pixel-translation

I don’t know how other engines handle the issue, but most don’t have the issue because of either their limitations or the way the engine wants you to handle assets. You don’t have to get technical, because they are practical. They just work. Some of them I know force you to work in integers (no sub-pixels allowed), which can often be why, but this is not always the case.

Out of the box, this has never been a problem with any framework or engine I have used except Unity.
All others don’t distort their pixels like Unity does with its Sprites.

With Unity, it is quite a significant problem as you can find post after post with this issue, and only sometimes is it resolved enough for people to be satisfied.

You will not find this to be a massive problem on any other 2D game forum.
Hence why Unity’s 2D rendering is flawed, no matter if this problem exists outside of Unity. Other engines/frameworks handle it, but Unity does not.

Like I said, there is no reason to get technical, when the reality requires an engine to be practical. Having such an awful problem is just unacceptable.

You can argue, facepalm, or -_- till you are blue in the face. I have worked with several engines, and basic rendering doesn’t have such silly frustrations or enormous flaws when dealing with those engines. You cannot tell me this is a problem which (practically) exists outside of Unity. Even if it does exist, the problem only exists for people working with Unity, as other engines handle things in a way as to discourage people from creating or having this flaw, or they handle the issue so as to resolve the issue in most cases. I’ve never worked with GameMaker, but I wouldn’t be surprised if this was not a problem when working with the engine. It is quite silly to have every user have such problems in Rendering- something that is probably the most important function of a game engine.

Especially when Unity is suppose to be a 2D supported engine after its 4.3 update.
It really is not ready to be called a 2D engine, as its 2D functionality is shoddy at best.
Argue semantics, but Unity is indeed trying to be both a 3D and 2D engine, and it is capable of both (obviously, any 3D engine is capable of 2D) but the 4.3 update was suppose to make it easier. The entire purpose of an engine is to provide functionality and various features. Having your 2D rendering functionality flawed like this is unacceptable. You might as well not have the functionality, so as to encourage users to choose another engine for 2D if applicable.

Fortunately, Unity’s strengths more than make up for this weakness- and then some. It would most likely not be on my list of engines to use on most 2D games though. It really needs to strengthen its 2D functionality, as so many people make 2D games with Unity. I would also not recommend the engine to others who wish to pursue 2D development, unless they wish to learn some nice lessons in component-based design. Absolutely love the GameObject-Component relationship of Unity, the Editor, etc.

TLDR: Practical > Technical. Unity2D rendering (at least for pixel perfect or retro pixel art) is not practical. If an engine’s rendering functionality is questionable, its usefulness is debatable. Unity is a great engine, but its 2D rendering blows hard lemon chunks.

Could you post what steps you are doing that is achieving these results?

I gather you have sprites on the screen, and then moving the camera? or the sprites? How are you moving what you are moving?

I am curious because I have only done a few projects with sprites/pixel perfect, and didn’t have any issues. (or maybe I didn’t notice them). I tried a quick repro of what you explained, and didn’t see any distortion, but I may not be doing all the steps you are.

Sure, I will post what I can after work. I have worked with 2d in Unity in the past, and I didn’t have as many problems or didn’t notice them.

It might be more noticeable just bc of the art.

I also did not have this problem when I edited textures and used SpritETile.

Thr major change is the addition of many things as their own gameobjects and sprite renderer.

When rendering large textures (my previous Tillman), or using The sprite renderer with my characters, the problem was not there or not noticeable.

Perhaps it has to deal with the dots needing to be so small and so inanimate. Or maybe it was not noticeable until I obsessed over it.
I did notice that an IDENTICAL problem occurs in the Sega game STARFLIGHT. Yet I never noticed through hundreds of hours played.

So it could be gameobjects transforms (always integers), unnoticeable unless you obsess, or what I am rendering.

It is not tje camera, as the problem disappears when the camera moves (it followedbthevplayer slowly). The problem was primarily when the camera stopped on an integer transform on certain Y positions (depending on screen resolution too)

I don’t understand why so many people MAKE pixel art. Compared to just drawing something with basic lines, shapes, and gradients, and then shrinking it, pixel art manages the impressive feat of being both more work and looking worse. A little bit of retro here and there is all well and good, but…

1 Like

It’s an issue that becomes a lot more noticeable with slower camera movements as well, which is what I’m guessing you’re having happen here?

While it has definitely become over-done now over the past few years, to say it looks “worse” is false. It’s a style, it’s a unique look, it doesn’t look worse, you just have less to work with. Do black white photos automatically always look worse than color photos, simply because there is less color detail? No. When executed well, any style can look amazing. Sword Sworcery and FEZ are great examples of just how well executed pixel art can be, but they are also sadly the main reasons why everyone has jumped on the pixel-art bandwagon… It’s the latest fad.

In the time and talent it takes to make a piece of pixel art, a better looking vector art could have been made. I’m open to the idea that there might somehow exist an exception, but I’m certainly not aware of any, and I don’t think it really matters. Odds are, if you find a terrific piece of pixel art, it could have been stunning otherwise.

But you don’t have less to work with. These games are almost entirely being made for the same modern platforms. If you’re making it actually run on an ancient platform, that would be one thing, but Unity, for one, doesn’t publish to outdated consoles or MS DOS. Frequently, pixels aren’t even rendered as pixels, which would be too small on modern displays, but as relatively large squares. Compared to the older platforms, this actually compounds the problem, making lines that used to look okay with the blurry pixels of the time, into jaggies. This isn’t even retro; pixel art didn’t look like that at the time!

An unnecessary and inappropriate metaphor. We are, at this time, perfectly capable of having pixelated photos, and aside from the occasional censorship or meta-photo, we essentially do not.

Absolutely, but that doesn’t mean that tying one hand behind your back just because other people did good work even with that limitation, is a good idea.

And do you think they’re improved by being pixelated? Or wouldn’t be improved by being smoother? Because I don’t.

I wonder if these people realize how much work goes into things like that?

Fez would not be improved, although it’s not technically pixel art since it’s 3D (calling it voxel art would be more appropriate). Anyway, it’s totally a matter of opinion. It’s pointless telling someone that it would “look better” if it wasn’t pixel art, because that’s just your opinion and not a fact. Deliberately adopting limitations and working with those is part of being art in the first place.

–Eric

Sure, it could have been stunning otherwise, but that’s not the point when it comes to ART. Under these arguments you make, we should then logically take it further and say “well it would look stunning as a photorealistic 3D model! there’s no point in making it vector art”.
Also, vector art isn’t actually that great for game art. And drawing a higher detailed sprite is going to take more time than simpler pixel art, I’m not sure why you would think not. More detail = more time. It also makes creating the animations immensely more complicated as you have to start taking into account a lot more detail.

It was implied that I meant you had less to work with in terms of resolution, in terms of color and detail,since in the context of the discussion, we were talking about art, not hardware…

No, it’s a fine metaphor. A pixelated photo is not the same thing, because it’s merely low resolution with no art-direction. Pixel art is low-resolution WITH art direction, you are controlling the look in a way that is visually appealing to most people (except you apparently). Pixel art is prevalent throughout media, so what you say is false.

It’s not about what’s a “good idea”. It’s about what a person likes, and how they want their game to look visually, every style gives a different feeling. Pixel art is a style, just as realistic 3D is, just as cartoony cellshaded 3D is, just as black white is, or hand drawn like SkullGirls, and so many other styles. You’re not tying a hand behind your back, you’re creating what your artistic vision is.

Why does it have to be “improved”, for it to be an option? It’s not improved, it’s merely different. If you’re not a fan of games like Risk of Rain, S&S, Fez, etc… Well, that’s your prerogative, but it doesn’t mean everyone else liking it is wrong.

Huh?

If you believe this style has no place, then you have a lot to learn about art design theory. Truly.

I know your pain. I have a couple of projects that require pixel perfect too.

But I don’t think it’s a flaw in Unity, it’s more like a lack of features to conveniently automate things, so we have to do these by hand. And since 2D features are quite new it’s probably safe to assume we’ll have them eventually.

Yes actually, the camera is very slow, and before when I had a faster camera (for testing) it wasnt even noticeable.