• 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
0
Question by Loius · Nov 24, 2012 at 11:28 PM · uvpixelresizeflicker

Atlased sprites flicker when resizing

I don't trust me to describe this well, so here's a video of it.

There are two 'health bars.' They both behave this same way:

When the object's scale is 1.0, 2.0, 4.0, etc, flickering happens. Otherwise, there is no flicker and it looks exactly as expected. The game requires the object to be displayed at a scale of 1.0

The bars change from red to green through a basic localScale.x = p, localScale.x = (1-p) for the green and red sides. I first tried just resetting the mesh vertices, but that had the same behaviour.

Upon closer inspection (you can see this in the video), the texture's pixels skew vertically, both ways - showing the bottom row of pixels from the sprites above and below this one in the atlas (!!), as well as making artifacts along the bright white line of the visible sprite.

The sprites for the bars are 16x16 blocks of a 2048x2048 texture.

As an experiment, I built a coroutine to loop over all sprites and set their localScale to Mathf.Sin(Time.time) (so everything squishes and expands over and over). Every single sprite suffers from this resize-flicker.

Is there a workaround for this that doesn't involve losing pixel perfection? Another way to implement accurate health bars with sprites, perhaps?

I'm contemplating implementing some kind of stupid resize function on sprites which forces them to snap to the nearest screen pixel or something.

Edit:

Here's a picture of the actual mesh construction going on. Can't render the actual sprites in pause mode 'cause my setup doesn't do the right stuff to the mesh: alt text

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 Loius · Nov 27, 2012 at 06:15 PM 0
Share

Resizing to exact pixel widths doesn't fix this, and makes the movement jerky. Joy.

avatar image Loius · Nov 29, 2012 at 11:50 PM 0
Share

Not sure how an answer got marked as accepted, but this very clearly is not z-fighting or answered. :P

1 Reply

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

Answer by ThePunisher · Nov 27, 2012 at 07:45 PM

That almost looks like z-fighting, have you tried seperating the textures out a little more in the Z axis? If you are using an orthographic camera then you won't notice a difference in offset, and the textures will stop z-fighting.

Comment
Add comment · Show 10 · 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 ThePunisher · Nov 27, 2012 at 07:47 PM 0
Share

Also, I would make sure there is no rotation being applied on either of the images.

avatar image Loius · Nov 27, 2012 at 08:32 PM 0
Share

There actually aren't any textures overlapping - the green and red are separate objects scaled to fit exactly in their spots.

I calculate the UVs in a 'rectangular' way (+/-width, +/- height), but I imagine - if I'm getting into float inaccuaracy land - they could be "rotated" as the object scales. No idea how to compensate for that if that's what's happening.

avatar image ThePunisher · Nov 27, 2012 at 09:30 PM 0
Share

Right, I'm talking about the objects on which the textures are on. Sorry I wasn't more specific.

If they are on the same Z position, they will produce the behavior I described.

avatar image Loius · Nov 28, 2012 at 06:44 AM 0
Share

Added an image to the question rather than try to figure out how to get one into a comment. ^_^

I'm pretty sure Z-fighting involves pieces of both images fighting for screen space over their entire conflict area (meaning where the bars overlap would flicker between red and green).

avatar image ThePunisher · Nov 28, 2012 at 08:34 PM 0
Share

Ah nice, that helps a lot.

Wait, so are you scaling both the red quad and the green quad? Why not have the red quad cover the entire possible area of the bar and scale the green quad shorter/longer, covering the red bar.

From the video it seems the part of the problem is the inconsistent scaling between the green and red quads.

I would also verify that there is ABSOLUTELY NO rotation on either quad. I could see how readjusting the size while the object is rotated from the current perspective can skew the object's look.

Show more comments

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

11 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

Related Questions

UV issue on pixel pallet from Blender 0 Answers

Pixels skew vertically as object scales horizontally 1 Answer

Assigning UV Map to model at runtime 0 Answers

Voxel texturing with single texture instead of texturesheet? 0 Answers

Error in ONE PARTICULAR scene: "Mesh doesn't have albedo UVs. Please create them in your modelling package." 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