• 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 Loius · Dec 01, 2012 at 05:50 PM · meshscalepixelflicker

Pixels skew vertically as object scales horizontally

I asked this before but it was magically marked as answered when it was clearly not answered, so I must ask again.

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.

This is not related to Z-fighting. The sprites for the bars are 16x16 blocks of a 2048x2048 texture, and every vertical column in the sprite is identical - some of the columns are being rendered one pixel above or below where they should be. The mesh isn't skewed, just which pixels are displayed.

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?

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 aldonaletto · Dec 01, 2012 at 08:37 PM 1
Share

Are these 3D objects or GUITextures? You can get pixel perfect results with GUITextures or GUI elements, but not with 3D world objects.

avatar image Loius · Dec 02, 2012 at 12:31 AM 0
Share

They are 3D objects. I was really hoping not to involve anything in GUI, 'cause I need to keep draw calls to a $$anonymous$$imum (and my existing setup means one draw call for all the gui).

Using GUI elements does give me pixel perfection, though, so thanks. I might have to go to that.

1 Reply

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

Answer by aldonaletto · Dec 02, 2012 at 01:15 AM

If you have to do it with 3D planes, use texture offset instead of changing the scale: create a texture half green and half red, and set the plane uv right point to 0.5 instead of 1.0, then set the texture offset x coordinate to 0.5 * p:

alt text


uvbar.png (4.5 kB)
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 Loius · Dec 02, 2012 at 07:51 AM 0
Share

I'm using a sprite sheet. The math makes my brain hurt. But this works perfectly, thank you very much. :D

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

Pixel Perfect Camera auto *zoom/scales* on different resolution 1 Answer

Is it possible to find the width of a text mesh? 6 Answers

Can you scale a Mesh independently of it's Collider? 1 Answer

Can I Duplicate The Default Cube Mesh To Give It Different Scale Factors? 0 Answers

Unity3D - Plane Scale To Pixel 0 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