Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by artie · Oct 24, 2013 at 06:55 AM · texture

Why are my pixels blurred? Strange antialiasing?

I am creating a texture in code, and setting the values. For some reason, I don't know, the pixels drawn are blurred. What is going on?

     public Texture2D texture;
 
 
     Color32[] outputPixels;
 
     void Start()
     {
         texture = new Texture2D(320, 240, TextureFormat.ARGB32, false);
         texture.wrapMode = TextureWrapMode.Clamp;
         texture.filterMode = FilterMode.Point;
         texture.anisoLevel = 1;
         texture.mipMapBias = -.5f;
         renderer.material.mainTexture = texture;
         outputPixels = new Color32[320*240];
         for (int y = 240 - 1; y >= 0; --y)
         {
             int outputIndex = y * 320;
             for (int x = 0; x < 320; ++x, srcIndex ++, ++outputIndex)
             {
                   // set every 8th column white, otherwise black
               outputPixels[outputIndex] = ((x & 7) == 7) ? Color.white : Color.black;
               outputPixels[outputIndex].a = 1;
             }
         }
         texture.SetPixels32(outputPixels);
         texture.Apply();
     }

alt text

I expect sharp white vertical lines every 8 pixels. I get grayness. Like antialiasing, but I don't know now to disable that???? Texture is applied to material with standard scale and offset. Could it have something to do with it not being power-of-two sized?

UPDATE: It does seem to be related to power-of-two. I changed it to 512x256 and the lines are sharp. HOWEVER this does not solve my problem, I need a non-power-of-two size!!

blur.jpg (33.4 kB)
Comment
Add comment · Show 2
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 meat5000 ♦ · Oct 24, 2013 at 04:17 PM 0
Share

What happens if you reduce your x count by 1?

Something to do with your pre-increment?

At a glance it looks like an overshooting image mask.

avatar image artie · Oct 24, 2013 at 04:53 PM 0
Share

I changed all pre- to post-increments, no change. The odd thing is the gray areas. Should be black or white. I have no idea how this is anti-aliasing itself (if that's what's happening)

1 Reply

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

Answer by Bunny83 · Oct 25, 2013 at 06:33 AM

The short answer is you can't prevent the resampling at runtime and the only solution is to use power of two textures.

We had this question a couple of times. Basically Non Power of Two textures are only used in the GUI system and only when imported in the Unity editor. The importer will actually create two versions of the texture (when the importer is set to GUI).Both textures are created as the next larger power of two texture. However the "normal" texture is resampled to the new texture size and the GUI-version is just padded with empty space.

The support of those padded GUI textures is only internal. There's no way (up to the current date) to create such a texture at runtime. Therefore: your only options are:

  • Don't create the texture in code and don't load it manually at runtime. (Of course only for GUI stuff. Any other use is still power of two resampled)

  • For GUI use, pad the texture yourself to the next power of two and handle the padding yourself. You can use GUI.DrawTextureWithTexCoords to handle the padding.

  • For any other use, you might just pad it the same way and adjust the texture coordinates

For more insight see this post by Aras.

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 artie · Oct 25, 2013 at 06:17 PM 1
Share

Since the texture being displayed is a processed web cam image (live video), option 3 is also what I concluded. I'll size it up to the next Po2 (512x256) and adjust the tiling and offset to make it fit. Thanks.

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.

Follow this Question

Answers Answers and Comments

18 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 avatar image avatar image

Related Questions

GUI Texture on Button Swap 3 Answers

Switching Between Textures 1 Answer

Creating a component from a button click 1 Answer

Texture change problem 0 Answers

One material for many objects with different textures 2 Answers


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