http://blog.csdn.net/costfine/article/details/46930473
It is found that most of the art adjusts the color of the HSV, because it is easy to adjust the hue (hue), saturation (saturation) and hue (value) separately. For example, people want to adjust the color of the red point, then only need to modify the hue, if you use RGB, you need to adjust 3 values, just increase the R value, in theory, just the red value is aggravated only. Even in the usual palette, most of them are based on HSV, such as the U3d palette:
颜色空间有很多中,RGB、HSL、HSV、CMYK...等等好多,如果有兴趣的话可以去搜搜。但我们这里只用HSV 。比如一张贴图是红色系的,我们要改成绿色系,只需要将hue值偏移到绿色值就好了。各种颜色空间转换的公式:http://www.easyrgb.com/index.php?X=MATH&H=22#text22
Method we know, the formula also has, the following directly write code.
Shader"TORNADO/COLORGRADATION_HSV" {Properties {Decal _maintex ("Maintex (RGB)",2D) ="White" {}Hue has a value range of 0-359. The other two is 0-1, here we set to 3, because times 3 is not necessarily able to exceed. _hue ("Hue", Range (0,359)) =0 _saturation ("Saturation", Range (0,3.0)) =1.0 _value ("Value", Range (0,3.0)) =1.0} subshader {Pass {Tags {"Rendertype" ="Opaque"} LODLighting Off Cgprogram#pragma vertex vert_img#pragma fragment Frag#include "unitycg.cginc" sampler2d _maintex; Half _hue; Half _saturation; Half _value;struct Input {float2 uv_maintex;};RGB to HSV FLOAT3 RGBCONVERTTOHSV (float3 RGB) {float R = Rgb.x,g = Rgb.y,b = rgb.z; FLOAT3 HSV;Float Max1=max (R,max (g,b));Float Min1=min (r,min (g,b));if (R = = max1) {hsv.x = (g-b)/(max1-min1);}if (G = = max1) {hsv.x =2 + (B-R)/(max1-min1); }if (B = = max1) {hsv.x =4 + (R-G)/(max1-min1); } hsv.x = hsv.x *60.0;if (hsv.x <0) hsv.x = hsv.x +360; HSV.Z=MAX1; Hsv.y= (max1-min1)/max1;return HSV; }HSV to RGB float3 Hsvconverttorgb (float3 HSV) {float r,g,b;FLOAT3 RGB;if (hsv.y = =0) {r=g=b=hsv.z;}else {hsv.x = hsv.x/60.0;int i = (int) hsv.x;float F = hsv.x-(float) I;float A = hsv.z * (1-HSV.Y);Float B = hsv.z * (1-HSV.Y * f);float c = hsv.z * (1-HSV.Y * (1-F));switch (i) {Case0:r = hsv.z; G = C; B = A;BreakCase1:r = b; G = hsv.z; B = A;BreakCase2:r = A; G = hsv.z; B = C;BreakCase3:r = A; G = b; B = hsv.z;BreakCase4:r = C; G = A; B = hsv.z; break; default:r = hsv.z; G = A; b = b; break;} } return float3 (r,g,b);} fixed4 Frag (v2f_img i): sv_target {fixed4 original = tex2d (_mainte x, I.UV); //get map original color FLOAT3 colorhsv; colorhsv.xyz = RGBCONVERTTOHSV (original.xyz); //converted to HSV colorhsv.x + = _hue; //adjust offset hue value colorhsv.x = Colorhsv.x%360; //more than 360 of the value starting from 0 colorhsv.y *= _saturation; //adjust saturation colorhsv.z *= _value; original.xyz = Hsvconverttorgb (colorhsv.xyz); //will adjust the HSV, convert to RGB color return original;} ENDCG}} FallBack "diffuse"}
the original and adjust the contrast after hue, like not playing fighting games before, two players selected the same character, then 2P color effect ...
The same can be applied to camera effects .... Instantly change the mood of the scene
Of course, you can also adjust the saturation and brightness ... The saturation is adjusted to 0 and it's a black-and-white picture.
Reference
http://blog.csdn.net/idfaya/article/details/6770414
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UNITYSHADER:HSV (hue, saturation, brightness) conversion