Shader "Unlit/ChooseContinent"
{ //2018年4月8日
//for ui地图高亮所有相同的颜色块
Properties
{
_MainTex("Texture", 2D) = "white" {}
_SwitchColor("SwitchColor",Int) = 0 //高光还是直接返回
_HighlightColor("HighlightColor",Color) = (0.498,1,0,0.3)//高光颜色
_ChooseR("ChooseR",Int) = 255//点击选择的颜色值
_ChooseG("ChooseG",Int) = 255
_ChooseB("ChooseB",Int) = 255
_ThresholdValue("ThresholdValue",Int) = 10//判断范围的阀值
_VertexOffset("VertexOffset",Vector) = (5,-15,0,0)//顶点偏移
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
Cull Back
Lighting Off
ZWrite Off
ZTest Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
#include "UnityUI.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
float4 _VertexOffset;
v2f vert(appdata_t IN)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.worldPosition = IN.vertex;
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition) - _VertexOffset;
OUT.texcoord = IN.texcoord;
return OUT;
}
sampler2D _MainTex;
float _SwitchColor;
float _Alpha;
float4 _ChooseColor;
float4 _HighlightColor;
int _ChooseR;
int _ChooseG;
int _ChooseB;
int _ThresholdValue;
float4 frag(v2f IN) : SV_Target
{
if (_SwitchColor == 0)
{
return 0;
}
// sample the texture
float4 col = tex2D(_MainTex, IN.texcoord);
return step(
3
, step(abs(_ChooseR - col.r * 255), _ThresholdValue)
+ step(abs(_ChooseG - col.g * 255), _ThresholdValue)
+ step(abs(_ChooseB - col.b * 255), _ThresholdValue)
)*_HighlightColor;
}
ENDCG
}
}
}