• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Kylotan · Jan 23, 2013 at 08:10 PM · texturesprite

How can I get Unity to stop resampling my sprites?

I am rendering sprites as a single texture on a quad. Unfortunately, Unity resamples the texture to the nearest power of two which affects the artwork when it is a different size (eg. 24x24). I can zoom in during play and see that the texture has become a 32x32 one. The texture is set to Point mode so bilinear filtering is off.

I have tried setting the asset to the 'GUI' texture mode, but it is still being resampled. Similarly if I go to 'Advanced' texture mode and leave the nearestPowerOfTwo mode on 'None', it is resampled then, as well.

Anybody have any suggestions?

Example image, Scene view on left, original asset on right: alt text

And a close-up of how the texture appears in the preview after importing, to show it was imported correctly: alt text

texture_sampling_issue.png (10.6 kB)
texture_sampling_issue_2.png (4.1 kB)
Comment
Add comment · Show 20
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Jan 23, 2013 at 08:45 PM 0
Share

How do you render into that texture? Do you use RenderTextures or regular textures? Do you create textures by script or are you exclusively using project assets? When you hit play and zoom in, hit pause, then select the object you suspect to have 32x32 in the scene view and find the texture in the inspector. What resolution does it give in the preview? Are any other settings off?

We need more information.

avatar image Kylotan · Jan 23, 2013 at 09:22 PM 0
Share

It is just a plain project asset, a PNG. The image in the preview is the original resolution on disk (24x24), but in Scene and Game view it's 32x32 with the resampling artifacts.

avatar image Kylotan · Jan 23, 2013 at 09:29 PM 1
Share

Yes, I counted the pixels. I posted the image so you can too. :) There is no bilinear sampling; it's set to Point mode. If I use a 32x32 asset it renders perfectly.

avatar image Wolfram · Jan 30, 2013 at 08:00 PM 1
Share

Sorry I didn't get back to you earlier. The answer is "yes, Unity resamples your textures, and no, you can't prevent it". See my answer for a more detailed explanation.

avatar image Wolfram · Jan 31, 2013 at 06:13 PM 1
Share

Summary of the white-alpha-pixel-problem: http://forum.unity3d.com/threads/168532-White-rims-around-transparent-textures-an-analysis

Show more comments

6 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Wolfram · Jan 23, 2013 at 10:05 PM

UPDATE: For reference: the whole internal-rescaling-to-POT-for-NPOT-textures issue is fixed in Unity 4 (tested 4.2.0)! The following discussion/answer is about older versions, such as Unity 3.5:

Assuming it really is a bug, I can at least suggest a workaround. It is ugly, tedious, and hackish, but it will resolve your problem:

  • pad your textures manually to be 32x32

  • either adapt your object UV to the new mapping scale (and maybe origin), or adapt the scale/offset settings in the material using the texture.

For example, extend your texture to the right and the bottom, to keep the "correct" texture segment in the upper left corner. Then you can set the texture scaling to 0.75/0.75 instead of 1/1 in the material.

If you keep your sprite centered while padding on all four sides, you'd have to adjust the offset, too.

EDIT:

I checked this again with an old testscene I did about this problem, and unfortunately it is still present (latest version tested: 3.5.7. The issue is actually fixed in 4.x (tested 4.2.0). Problem exists at least since 2.6.

====> Any non-power-of-two-textures will be resampled to the nearest(?) power-of-two, even if NPOT-scaling is explicitly set to "None". An exception are GUI textures, i.e. if you use such a texture for OnGUI() or in GUITexture objects. But any such texture applied to a "regular" GameObject will no longer be pixel-perfect compared to the original texture. See also Aras' answer here (although he does not explicitly mention that the scaling also happens if you set NPOT-scaling to "None").

I guess it is debatable whether this is a bug or a feature - I consider it a bug, since if I explicitly set the texture scaling to "leave-the-texture-alone-and-dont-use-NPOT-scaling", I expect the system to do exactly that. If it is unable to do that due to hardware limitations (or whatever other reasons) it at the very least needs to explain this drawback in the documentation.

EDIT2: Woops, as @Bunny83 pointed out, it is documented, somewhere in the fine print ;-)

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jan 30, 2013 at 08:24 PM 0
Share

Yes, it's not really documented in a way that it's easy to find.

Btw, aras clearly says that non power of two textures, if used for anything but GUI, uses a second version of the texture which is scaled to the next higher power of two texture.

avatar image Kylotan · Jan 30, 2013 at 08:28 PM 1
Share

What isn't so clear in Aras's message is that you can't get to that padded texture yourself. Doesn't this make the whole dropdown box for how to treat NPOT textures pointless?

avatar image Wolfram · Jan 30, 2013 at 08:30 PM 0
Share

@Bunny83: Yes, but when I was first reading that I was hoping for an addendum such as "Yes, this even is true if you explicitly disable NPOT-scaling". The way he wrote it it is unclear, since it also describes the default settings of the import behaviour: scaling to the next (well, ok: nearest...) power of two.

avatar image Wolfram · Jan 30, 2013 at 08:34 PM 0
Share

@$$anonymous$$ylotan: Indeed it does, except for GUITextures and GUI.DrawTexture.

avatar image Bunny83 · Jan 31, 2013 at 02:44 PM 0
Share

Btw, nearest is not the same as next (it that'S really what aras ment). Next would be like the setting "ToLarger" so the next greater power of two size. Nearest could be the next larger or the next smaller.

avatar image
2

Answer by Bunny83 · Jan 30, 2013 at 08:07 PM

Read the section about Texture Sizes. As you can see when NPOT textures are used as "normal" textures they are converted internally to POT textures. I'm not sure why they do that, but it seems you can't disable this behaviour. It might be for compatibility with graphics cards which don't support NPOT textures.

However the easiest and best fix is to resize your texture to 32x32 (add padding). NPOT textures are even slower. The graphics card memory is optimised for POT sizes. Even NPOT textures will use the next higher POT size alignment in graphics memory.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jan 30, 2013 at 08:12 PM 0
Share

Btw, your princess fits into 16 pixels horizontally, so when using a 16x32 texture it's even smaller than a 24x24 texture ;)

But maybe in some cases it might be larger (sprite animations?). The best way is of course to use an atlas like @$$anonymous$$alikDrako said, but it requires a bit more UV fiddling

avatar image Kylotan · Jan 30, 2013 at 08:13 PM 0
Share

The link to the Texture Sizes part of the docs is a bit contradictory - one part says the texture will be padded, another part says it will be stretched. Hopefully they can fix this in the future.

avatar image Kylotan · Jan 30, 2013 at 08:14 PM 0
Share

As for texture atlases, they are a complication that most simple sprite systems will want to avoid. Ideally Unity would perform atlasing for you, as it does for fonts.

avatar image Wolfram · Jan 30, 2013 at 08:18 PM 0
Share

@$$anonymous$$ylotan: Yes, the docs page is incomplete/misleading. In the important section (the explanation of the parameter), they only mention GUITextures, and I guess for them it will be padded (so even they don't use the NPOT-version internally). However, further below in the "fine print", it mentions the rescaling (neglecting to mention that this does not apply to GUITextures...)

avatar image
1

Answer by bopie · Feb 19, 2014 at 05:34 AM

Do you set the color format to TrueColor? Its default value is 'Compressed' and will be blurred.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image K0ndor · May 20, 2016 at 02:57 PM 0
Share

Yup, I had similiar problem with my 8x8 textures. Changing from "compressed" to "16bits" fixed it.

avatar image
0

Answer by mescalin · Jan 30, 2013 at 07:20 PM

i am not sure that is really possible in unity, i think my approach would be to make them textures a much higher resolution.

actually i have some 2d art left over from my construct classic obsession, i have all this scaled up 4x from 16x16 to sharpen the aliasing. I imagine in unity I'd scale up even more still and maybe customize the actual edges depending how the alpha goes down.

basically you're gonna just have to use a tonne of more memory and get down and dirty with it but in a systematic way preferably, I'd suggest investigating programmable batch type image manipulation tool like imagemagic so you can mass process stuff

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by MalikDrako · Jan 30, 2013 at 07:38 PM

That is happening because you are using a texture with dimensions that are not a power of 2. You can stop Unity from resizing the texture by either using the GUI texture type or Advanced with "Non Power of 2" set to "None," but I'm not sure how much of an impact this will have on performance

From the Texture documentation:

It is possible to use other (non power of two) texture sizes with Unity. Non power of two texture sizes work best when used on GUI Textures, however if used on anything else they will be converted to an uncompressed RGBA 32 bit format. That means they will take up more video memory (compared to PVRT(iOS)/DXT(Desktop) compressed textures), will be slower to load and slower to render (if you are on iOS mode). In general you'll use non power of two sizes only for GUI purposes.

You could also combine multiple sprites onto a single larger texture and change the UVs of the quad to get just the sprite you want. This is called a texture atlas

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Jan 30, 2013 at 07:49 PM 0
Share

This is not correct - read on in the document right after the paragraph you quoted. See my answer, as well as the discussion in the question.

Your last sentence is valid.

  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UI Sprite very pixelated 1 Answer

Mask a texture onto sprite? 0 Answers

Create sprite renderer using custom material 2 Answers

How do you crop a Texture2d 1 Answer

Moved my projects to Unity 5, now all my sprites are set to "Tight" mesh generation instead of "Full Rect". Easy way to automagically set it all back? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges