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
2
Question by Eowyn27 · Feb 24, 2014 at 02:49 PM · colorrgb

Color: Why is color with four attributes and a value of 0 to 1?

I noticed in the document that Color has four attribute and a value of 0 to 1. I'm not understanding the concept well. I want to understand the concept.

e.g. I've seen this:

 new Color(1f, 0f, 0f, 0.4f); 

Let's say I have a color gray and I want to use the Color attribute. I know that gray's rgb value is (192,192,192). How do I convert that to a value from 0 to 1? Why is Color written from 0 to 1?

Can someone explain the concept and why Unity uses something like the new Color declared above? I can't find a good explanation online.

Comment
Add comment
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

3 Replies

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

Answer by komodor · Feb 24, 2014 at 02:52 PM

it's RGBA red green blue alpha

minimum value is 0, maximum is 1

it means 0 = 0, 1 = 255 for RGB and 0 = 0, 1 = 100 for alpha

it's actually pretty simple and pretty good for purposes of programmer and that's the reason why it's that ... number from 0 to 255 is nothing more than minimum and maximum of some range, but if you want to calculate with color you always need to divide it by maximum (so by 255) first and that's the reason unity skips this step

your example mean red color with 40% transparency (photoshop values)

gray color as you describe it would be new Color(0.75f, 0.75f, 0.75f); (the alpha is optional) you'll get the number by dividing 192 / 255

to work with unity i was forced to forget my old habbits like thinking in this photoshop RGB or thinking about animation as it consists from frames ... and it works even better

Comment
Add comment · 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 Owen-Reynolds · Feb 24, 2014 at 04:28 PM 1
Share

"0 to 255 is nothing more than $$anonymous$$imum and maximum of some range"

But 0-255 isn't arbitrary. Who would pick that? Your screen probably uses 32bit RGBA. That means each channel is stored in a byte, which has a range of 0-255. In other words, a pixel really does have 256 brightness steps for each color.

avatar image Eowyn27 · Feb 27, 2014 at 07:01 PM 1
Share

Thank you for the explanation $$anonymous$$omodor! That makes me understand it a little better now.

avatar image
1

Answer by edve98 · Feb 24, 2014 at 03:07 PM

Why Unity uses this format I have no Idea, but you can always use color32: http://docs.unity3d.com/Documentation/ScriptReference/Color32.html

Comment
Add comment · 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 Kiloblargh · Feb 24, 2014 at 04:49 PM 1
Share

This. If you want to limit yourself to 256 integer values for each channel, use Color32 and you'll be happy; and it give better performance.

A float value between 0 and 1 can contain a lot more information than 256 integers. (I'm not going to do the math right now to figure out how much more, exactly.)

For still images, 32 bits per pixel should be enough for anyone, ( it's all most graphics cards support anyway) unless your audience is mantis shrimp. But 32-bit color is really 8-bit per channel precision, so you could still get banding in very shallow gradients or jumping in very slow fades, whereas the Color format lets you blend around colors effectively losslessly as many times as you like before sending them to the card.

Also 64-bit color is co$$anonymous$$g soon; once that becomes a an established standard, graphics snobs will expect no less.

avatar image Riddlah Kiloblargh · Oct 04, 2017 at 11:36 AM 0
Share

Thank you very much for mantis shrimp enlightment :)

avatar image
1

Answer by Owen-Reynolds · Feb 24, 2014 at 04:26 PM

0-1 RGBA has always been the official format used inside all graphics cards and shaders. Because of that, programmers tend to use 0-1 for colors (since all colors are going to into a shader at some point.) When I first looked at Unity, seeing they used 0-1 for Color variables was one of the things that convinced me they knew what they were doing.

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

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

22 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

Related Questions

A node in a childnode? 1 Answer

How do I change colors of an axis? 1 Answer

How to change the color using "renderer.material.color"? 2 Answers

Problem with GUITexture.color.a 2 Answers

Change Color of Object Based on Shape Covering It 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