ColorReplacement.shader 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Sprites/ColorReplacement"
  3. {
  4. Properties
  5. {
  6. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
  7. _Color ("Tint", Color) = (1,1,1,1)
  8. _ReplacedColor ("ReplacedColor", Color) = (0.5,0.5,0,1)
  9. _NewColor ("New Color", Color) = (0,0,0,0)
  10. [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
  11. }
  12. SubShader
  13. {
  14. Tags
  15. {
  16. "Queue"="Transparent"
  17. "IgnoreProjector"="True"
  18. "RenderType"="Transparent"
  19. "PreviewType"="Plane"
  20. "CanUseSpriteAtlas"="True"
  21. }
  22. Cull Off
  23. Lighting Off
  24. ZWrite Off
  25. Fog { Mode Off }
  26. Blend One OneMinusSrcAlpha
  27. Pass
  28. {
  29. CGPROGRAM
  30. #pragma vertex vert
  31. #pragma fragment frag
  32. #pragma multi_compile DUMMY PIXELSNAP_ON
  33. #include "UnityCG.cginc"
  34. struct appdata_t
  35. {
  36. float4 vertex : POSITION;
  37. float4 color : COLOR;
  38. float2 texcoord : TEXCOORD0;
  39. };
  40. struct v2f
  41. {
  42. float4 vertex : SV_POSITION;
  43. fixed4 color : COLOR;
  44. half2 texcoord : TEXCOORD0;
  45. };
  46. fixed4 _Color;
  47. fixed4 _ReplacedColor;
  48. fixed4 _NewColor;
  49. v2f vert(appdata_t IN)
  50. {
  51. v2f OUT;
  52. OUT.vertex = UnityObjectToClipPos(IN.vertex);
  53. OUT.texcoord = IN.texcoord;
  54. OUT.color = IN.color * _Color;
  55. #ifdef PIXELSNAP_ON
  56. OUT.vertex = UnityPixelSnap (OUT.vertex);
  57. #endif
  58. return OUT;
  59. }
  60. sampler2D _MainTex;
  61. fixed4 frag(v2f IN) : SV_Target
  62. {
  63. fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
  64. c.rgb *= c.a;
  65. if(c.r == _ReplacedColor.r && c.g == _ReplacedColor.g && c.b == _ReplacedColor.b)
  66. {
  67. c = _NewColor;
  68. }
  69. return c;
  70. }
  71. ENDCG
  72. }
  73. }
  74. }