- Home /
Shader color comprasion works only with red component of Color.
Hi, guys. So, basically, I'm trying to create a shader for province highliting, like in Crusader Kings or Eropa Universalis. For now it is supposed to work like so: I have 2 textures - for geography and for provinces. Each province is a unique-colored blob on a map. Shader has a Color property, which determines what province to highlight. But something goes wrong, and, for example (0.5, 0.1, 0.4, 0.1) == (0.5, 0.0, 1.0, 0.2) equals True, while the same with 0.5 and 0.6 in red component equals to False, which is intented. As you can see, in my case colors are equal if their red components are equal, which is quite weird. So, what can cause such behaviour? How can I fix it? See code below.
P.S. Sorry for my english.
Shader "Custorm/ProvinceShader"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_HighlightColor ("Hightlight color", Color) = (1,1,1,1)
_MainTex ("Main Texture", 2D) = "white" {}
_ProvinceTex ("Province Texture", 2D) = "white" {}
_HighlightLevel ("Highlight Level", float) = 0
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 _Color;
fixed4 _HighlightColor;
sampler2D _MainTex;
sampler2D _ProvinceTex;
float _HighlightLevel;
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 texcol = tex2D (_MainTex, i.uv);
texcol.r = texcol.r + _HighlightLevel * (tex2D (_ProvinceTex, i.uv) == _HighlightColor);
texcol.g = texcol.g + _HighlightLevel * (tex2D (_ProvinceTex, i.uv) == _HighlightColor);
texcol.b = texcol.b + _HighlightLevel * (tex2D (_ProvinceTex, i.uv) == _HighlightColor);
//texcol.r = texcol.r + _BlendAlpha * (tex2D (_ProvinceTex, i.uv).r);
//texcol.g = texcol.g + _BlendAlpha * (tex2D (_ProvinceTex, i.uv).g);
//texcol.b = texcol.b + _BlendAlpha * (tex2D (_ProvinceTex, i.uv).b);
return texcol * _Color;
}
ENDCG
}
}
Fallback "Transparent/VertexLit"
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613191027im_/https://answers.unity.com/themes/thub/images/avi.jpg)