NGUI的UISprite增加灰度处理

作者:追风剑情 发布于:2015-12-3 14:23 分类:NGUI

一、修改Unlit - Transparent Colored.shader

  1. Shader "Unlit/Transparent Colored"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
  6. }
  7. SubShader
  8. {
  9. LOD 100
  10. Tags
  11. {
  12. "Queue" = "Transparent"
  13. "IgnoreProjector" = "True"
  14. "RenderType" = "Transparent"
  15. }
  16. Cull Off
  17. Lighting Off
  18. ZWrite Off
  19. Fog { Mode Off }
  20. Offset -1, -1
  21. Blend SrcAlpha OneMinusSrcAlpha
  22. Pass
  23. {
  24. CGPROGRAM
  25. #pragma vertex vert
  26. #pragma fragment frag
  27. #include "UnityCG.cginc"
  28. struct appdata_t
  29. {
  30. float4 vertex : POSITION;
  31. float2 texcoord : TEXCOORD0;
  32. fixed4 color : COLOR;
  33. };
  34. struct v2f
  35. {
  36. float4 vertex : SV_POSITION;
  37. half2 texcoord : TEXCOORD0;
  38. fixed4 color : COLOR;
  39. };
  40. sampler2D _MainTex;
  41. float4 _MainTex_ST;
  42. v2f vert (appdata_t v)
  43. {
  44. v2f o;
  45. o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  46. o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  47. o.color = v.color;
  48. return o;
  49. }
  50. //修改此函数
  51. fixed4 frag (v2f i) : COLOR
  52. {
  53. fixed4 col = tex2D(_MainTex, i.texcoord);
  54. fixed grey = dot(col.rgb, fixed3(0.299, 0.587, 0.114));
  55. fixed4 col_grey = fixed4(grey, grey, grey, col.a);
  56. fixed g = step(i.color.r + i.color.g + i.color.b, 0.001);
  57. col = col * i.color * g + col_grey * (1 - g);
  58. return col;
  59. }
  60. ENDCG
  61. }
  62. }
  63. }

运行效果

run.png

标签: NGUI

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号