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 e_tip · Jun 03, 2014 at 02:25 PM · ioscolorpicker

Texture2d color transformation made the right way

Hi everyone! i've developed a little colorpicker for my unity app. To obtain it i've used a GUI.RepeatButton with a Texture2d as background. I've used a texture2d and not a shader ( as seen in others colorpicker in asset store) because i need that colors will be in a defined range so don't want all the rgb values. By the way this works flawlessy. now i've been asked to add saturation and brightness controls, but updating the texture2d is very very very slow I've used this code

 private void updateTexture(){
         saturation = newSaturation;
         brightness = newBrightness;
         if (newSaturation == 1 && newBrightness == 1) {
             Color[] colors = texture.GetPixels ();
             modifiedTexture.SetPixels (colors);
             modifiedTexture.Apply ();
         } else {
             Color[] colors = texture.GetPixels ();
             float pr=0.299f;
             float pg=0.587f; 
             float pb=0.144f;
             for (int i = 0; i < colors.Length; i++) {
                 if(brightness < 1){
                     colors[i].r = colors[i].r*brightness;
                     colors[i].g = colors[i].g*brightness;
                     colors[i].b = colors[i].b*brightness;
                 }
                 if(saturation < 1){
                 float p = Mathf.Sqrt(Mathf.Pow(colors[i].r,2)*pr+ Mathf.Pow(colors[i].g,2)*pg+ Mathf.Pow(colors[i].b,2)*pb);
                     colors[i].r = p + ((colors[i].r-p) * saturation);
                     colors[i].g = p + ((colors[i].g-p) * saturation);
                     colors[i].b = p + ((colors[i].b-p) * saturation);
                 }
 
             }
             modifiedTexture.SetPixels (colors);
             modifiedTexture.Apply ();
         }

but as the image is 700x700 pixels on mobile device is quite slow. is there any smart way to improve performance of this colorpicker ? thanks in advance

alt text

schermata 2014-06-03 alle 16.03.55.png (113.4 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Nabeel Saleem · Jun 03, 2014 at 04:24 PM

Select the texture which becomes pixelated.

-From import settings

Texture type=texture

Filter mode=Trilinear

Max size=max

Format=truecolor

and click apply

Quick fix GUI (source)

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

Answer by supernat · Jun 03, 2014 at 02:37 PM

Some things pop out to me. The read/set pixels are what's killing your performance.
1) you could only update the image once the sliders stop sliding (I know, not the best approach).
2) You could reduce the size of the texture so that while sliding you are adjusting a much smaller version of the texture so that brightness can be perceived even though the texture will enter a sort of blurry/degraded look during the adjustment, then return to the full size after the sliding is complete.
2a) Why not just update the small square texture's brightness and saturation while sliding and the entire image afterward.

3) You may need to use a shader pass just for the brightness if that's possible. I understand that you need to keep it as a texture lookup for the actual colors, but you can use a shader with extra brightness/saturation parameters. Although the saturation may be difficult since you are limited in your color scope, the brightness should work without a hitch.
4) Get rid of the Pow() method, just multiply the input by itself (small improvement, probably negligible, but helps code readability)

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

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Do our company need a Facebook business account for integrating our unity game? 1 Answer

Playing ipod audio... 0 Answers

Animation Freeze, If minimize and reopen the game, It is OK 0 Answers

In app purchase of content 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