Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

Texture2d color transformation made the right way

$
0
0
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][1] [1]: /storage/temp/27242-schermata+2014-06-03+alle+16.03.55.png

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>