• 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
Question by Chimera3D · Jun 06, 2014 at 08:47 AM · texturecolorwronggetpixelsetpixel

GetPixel Returning Inaccurate Color

I have a script that simply assigns a float value to the alpha channel of a pixel in a texture, however when calling get pixel on the exact same position the value is slightly off which is actually causing a big problem in my case. The code is all fairly simple:

 texture.SetPixel(x, y, new Color (0, 0, 0, originalValue));
 float returnedValue = texture.GetPixel(x, y).a;
 print("0v: " +originalValue + " Rv: " +returnedValue);

Here are the results:

alt text

GetPixel seems to be rounding numbers to seemingly arbitrary values. Once again these values have to be exactly the same, I can't really work around that in any way. Please tell me there is a fix for this. Is there?

screenshot.png (64.6 kB)
Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Graham-Dunnett · Jun 06, 2014 at 10:40 AM

If you want the data to be exactly the same you'll need to create a texture that uses a floating point format for RGBA. That probably means you need to create a RenderTexture in the ARGBFloat format. To understand what you see, multiply your originalValue by 255, and remove the fractional part, to get the value that will be stored in your 32-bit RGBA texture. Then divide that number by 255 and you'll see the returnedValue. There's nothing arbitrary going on.

Comment
Bunny83
Chimera3D
Loius

People who like this

3 Show 2 · 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 Chimera3D · Jun 06, 2014 at 03:35 PM 0
Share

Ah, I knew that the conversion from Color to Color32 had to convert from the 0...1 system to the 0...255 system, but I didn't know that it removed the fractional part of the values as well. So, just to confirm this, I have to use render textures if I don't want the fractional part removed?

avatar image Loius · Jun 06, 2014 at 04:01 PM 0
Share

Looks like it. Texture2D seems to be limited to ARGB32.

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

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

Related Questions

create readable colour map 1 Answer

I'm trying to change a material, texture or color and it doesnt work 0 Answers

adding texture to vertex color darkens color 0 Answers

How to have correct color on imGUI Buttons (as dynamic textures) avoiding multiply effect ? 1 Answer

Weird Vertex Shader Behaviour 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