Advertisement
Guest User

Color replace shader

a guest
May 12th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2.  
  3. Shader "Custom/Sprite Color Swap"
  4. {
  5.     Properties
  6.     {
  7.         _MainTex("Sprite", 2D) = "white" {}
  8.         _Color("Color", Color) = (1,0,1,1)
  9.         _IgnoreColorA("Ignore Color A", Color) = (1,0,1,1)
  10.         _IgnoreColorB("Ignore Color B", Color) = (1,0,1,1)
  11.         _IgnoreColorC("Ignore Color C", Color) = (1,0,1,1)
  12.     }
  13.     SubShader
  14.     {
  15.         Tags
  16.         {
  17.             "RenderType" = "Opaque"
  18.             "Queue" = "Transparent+1"
  19.         }
  20.  
  21.         Pass
  22.         {
  23.         ZWrite Off
  24.         Blend SrcAlpha OneMinusSrcAlpha
  25.  
  26.         CGPROGRAM
  27.         #pragma vertex vert
  28.         #pragma fragment frag
  29.         #pragma multi_compile DUMMY PIXELSNAP_ON
  30.  
  31.         sampler2D _MainTex;
  32.         float4 _Color;
  33.         float4 _IgnoreColorA;
  34.         float4 _IgnoreColorB;
  35.         float4 _IgnoreColorC;
  36.  
  37.         struct Vertex
  38.         {
  39.             float4 vertex : POSITION;
  40.             float2 uv_MainTex : TEXCOORD0;
  41.             float2 uv2 : TEXCOORD1;
  42.         };
  43.  
  44.         struct Fragment
  45.         {
  46.             float4 vertex : POSITION;
  47.             float2 uv_MainTex : TEXCOORD0;
  48.             float2 uv2 : TEXCOORD1;
  49.         };
  50.  
  51.         Fragment vert(Vertex v)
  52.         {
  53.             Fragment o;
  54.  
  55.             o.vertex = UnityObjectToClipPos(v.vertex);
  56.             o.uv_MainTex = v.uv_MainTex;
  57.             o.uv2 = v.uv2;
  58.  
  59.             return o;
  60.         }
  61.  
  62.         float4 frag(Fragment IN) : COLOR
  63.         {
  64.             half4 c = tex2D(_MainTex, IN.uv_MainTex);
  65.  
  66.             if (c.r == _IgnoreColorA.r && c.g == _IgnoreColorA.g && c.b == _IgnoreColorA.b)
  67.             {
  68.                 return c;
  69.             }
  70.             else if (c.r == _IgnoreColorB.r && c.g == _IgnoreColorB.g && c.b == _IgnoreColorB.b)
  71.             {
  72.                 return c;
  73.             }
  74.             else if (c.r == _IgnoreColorC.r && c.g == _IgnoreColorC.g && c.b == _IgnoreColorC.b)
  75.             {
  76.                 return c;
  77.             }
  78.             else if (c.a == 0)
  79.             {
  80.                 return c;
  81.             }
  82.             else
  83.             {
  84.                 return _Color;
  85.             }
  86.         }
  87.             ENDCG
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement