标签:参考 hit 通过 rac back file tps fuse 为什么
Shader "Custom/TeamMaskRgb" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _From("From Color",Color) = (1,1,1,1) _To("To Color",Color) = (1,1,1,1) _RgbRange("Rgb Range",Range(0,1))=0.1 } SubShader { Tags { "RenderType"="Opaque" } LOD 150 CGPROGRAM #pragma surface surf Lambert noforwardadd sampler2D _MainTex; fixed4 _From; fixed4 _To; fixed _RgbRange; struct Input { float2 uv_MainTex; } ; void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex); // 老师傅们都说不要用if,所以就改成step了! fixed con = step(abs(_From.r-c.r),_RgbRange); con = con + step(abs(_From.g-c.g),_RgbRange); con = con + step(abs(_From.b-c.b),_RgbRange); con = step(3,con); o.Albedo = lerp(c.rgb,c.rgb+_To-_From,con); o.Alpha = c.a; } ENDCG } Fallback "Mobile/VertexLit" }
Shader "Custom/TeamMaskRgbEx1" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _From ("From Color", Color) = (1,1,1,1) _To ("To Color", Color) = (1,1,1,1) _Range ("Range", Range (0.0, 2.0)) = 0.01 } SubShader { Tags { "RenderType"="Opaque" } LOD 150 CGPROGRAM #pragma surface surf Lambert noforwardadd sampler2D _MainTex; fixed4 _From; fixed4 _To; half _Range; struct Input { float2 uv_MainTex; } ; void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex); fixed colorDistance = (c.r - _From.r)*(c.r - _From.r) + (c.g - _From.g)*(c.g - _From.g) + (c.b - _From.b)*(c.b - _From.b); o.Albedo = lerp(c.rgb,(_To.rgb - _From.rgb + c.rgb), saturate(1 - colorDistance / (_Range * _Range))); o.Alpha = c.a; } ENDCG } Fallback "Mobile/VertexLit" }
Shader "Custom/TeamMaskHue" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _From("From Color",Color) = (1,1,1,1) _To("To Color",Color) = (1,1,1,1) _FaultTolerant("hue fault-tolerant",range(0,359)) = 2 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Standard fullforwardshadows sampler2D _MainTex; struct Input { float2 uv_MainTex; } ; fixed4 _Color; fixed4 _From; fixed4 _To; float _FaultTolerant; float getHue(float3 col) { float r=col.r,g=col.g,b=col.b; float _max = max(r,max(g,b)); float _min = min(r,min(g,b)); float _gradient = _max - _min; float ret = 0; if(_max == r) { ret = (g-b)/_gradient; } else if(_max == g) { ret = 2 + (b-r)/_gradient; } else if(_max == b) { ret = 4 + (r-g)/_gradient; } ret = ret*60.0; if(ret<0) { ret = ret + 360; } return ret; } void surf (Input IN, inout SurfaceOutputStandard o) { fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; float hc = getHue(c.rgb); float hFrom = getHue(_From.rgb); float differ = abs(hc-hFrom); differ = lerp(differ,abs(differ-360),step(180,differ)); o.Albedo = lerp(c.rgb,c.rgb - _From.rgb + _To.rgb, step(differ,_FaultTolerant)); o.Alpha = c.a; } ENDCG } FallBack "Diffuse" }
Shader "Custom/TeamMaskFinal" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _From("From Color",Color) = (1,1,1,1) _To("To Color",Color) = (1,1,1,1) _HError("Hue Error",range(0,1)) = 0 // 允许的色相误差 _SError("Saturation Error",range(0,1)) = 0 // 允许的饱和度误差 _VError("Brightness Error",range(0,1)) = 0 // 允许的亮度误差 } SubShader { Tags { "RenderType"="Opaque" } LOD 150 CGPROGRAM #pragma surface surf Lambert noforwardadd sampler2D _MainTex; fixed4 _From; fixed4 _To; fixed _HError; fixed _SError; fixed _VError; struct Input { float2 uv_MainTex; } ; fixed3 RGBtoHSV(fixed3 c) { fixed4 K = fixed4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); fixed4 p = lerp(fixed4(c.bg, K.wz), fixed4(c.gb, K.xy), step(c.b, c.g)); fixed4 q = lerp(fixed4(p.xyw, c.r), fixed4(c.r, p.yzx), step(p.x, c.r)); float d = q.x - min(q.w, q.y); float e = 1.0e-10; return fixed3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); } fixed3 HSVtoRGB(fixed3 c) { fixed4 K = fixed4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); fixed3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www); return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y); } void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex); fixed3 cHSV = RGBtoHSV(c); fixed3 FromHSV= RGBtoHSV(_From); fixed3 ToHSV= RGBtoHSV(_To); fixed diffHue = abs(cHSV.x-FromHSV.x); diffHue = lerp(diffHue,abs(diffHue-1),step(0.5,diffHue)); fixed con = step(diffHue,_HError); con = con + step(abs(cHSV.y-FromHSV.y),_SError); con = con + step(abs(cHSV.z-FromHSV.z),_VError); con = step(2.5,con); fixed3 ret = cHSV + ToHSV - FromHSV; // ret.x = lerp(ret.x,ret.x-1,step(1,ret.x)); // ret.x = lerp(ret.x,ret.x+1,step(ret.x,0)); o.Albedo = lerp(c.rgb,HSVtoRGB(ret),fixed3(con,con,con)); o.Alpha = c.a; } ENDCG } Fallback "Mobile/VertexLit" }
标签:参考 hit 通过 rac back file tps fuse 为什么
原文地址:http://www.cnblogs.com/veboys/p/6944122.html