In my game, I have a bunch of territories. These territories have a shader that allows me to draw an outline around the border of the territory. The outline is inside the edge of the territory. I can control many settings, such as the border color, border thickness, etc.
I do a pathfind from the selected territory to the one I’m pointing at and I hilite each territory that is part of the path by drawing its border in yellow instead of black. (I hilite the last territory in white instead of black).
So, this works but the hilite looks terrible. Most of the time the border is sort of a crosshatch pattern on black and yellow or black and white. In a few places, the line comes through as a solid yellow, which looks a lot better but is still not the best.
How do I go about fixing this? I don’t know if it makes any difference, but I’m developing this for a Quest 2.
I’m attaching the shader I use and a video showing the problem.
Shader "ConquestVR/InternalLine"
{
Properties
{
_FillColor("Fill Color", Color) = (1,0,0,0)
_BorderColor("Border Color", Color) = (0,0,0,1)
_HilitedFillColorScale("Selected Color Scale", Range(0.5, 1)) = 0.9
_HilitedBorderColor("Hilited Border Color", Color) = (0,0,0,1)
_SelectedFillColor("Selected Fill Color", Color) = (1,0,0,0)
_SelectedBorderColor("Selected Border Color", Color) = (1,0,0,0)
_SelectedPulseSpeed("Selection Pulse Speed", Range(1.0, 10)) = 3.75
_PathHiliteFillColorScale("Path Hilite Color Scale", Range(0.5, 1)) = 0.9
_PathHiliteBorderColor("Path Hilite Border Color", Color) = (0,0,0,1)
_MainTex("Texture", 2D) = "white" {}
_BorderWidth("Border width", Range(0, 1)) = 0.1
}
SubShader
{
Tags { "Queue"="Geometry" "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#pragma shader_feature SELECTED
#pragma shader_feature HILITED
#pragma shader_feature PATH_HILITE
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.color = fixed4(v.color.rgb, v.color.a);
return o;
}
float4 _FillColor;
float4 _BorderColor;
float _HilitedFillColorScale;
float4 _HilitedBorderColor;
float4 _SelectedFillColor;
float4 _SelectedBorderColor;
float _SelectedPulseSpeed;
float _PathHiliteFillColorScale;
float4 _PathHiliteBorderColor;
float _BorderWidth;
fixed4 frag (v2f i) : Color
{
// Inside the if is the internal color
if (i.color.g >= _BorderWidth)
{
#if SELECTED
// When selected, we pulsate between the regular fill color and the selected fill color
float t = _Time[1] * _SelectedPulseSpeed;
float negOneToPosOne = sin(t);
float zeroToOne = (negOneToPosOne + 1.0f) / 2.0f;
float base = zeroToOne;
float extra = 1.0f - base;
return (base * _SelectedFillColor) + (extra * _FillColor);
#elif HILITED
float4 outColor = float4(_FillColor.rgb * _HilitedFillColorScale, _FillColor.a);
return outColor;
#elif PATH_HILITE
float4 outColor = float4(_FillColor.rgb * _PathHiliteFillColorScale, _FillColor.a);
return outColor;
#else
return _FillColor;
#endif
}
// Down here is for border
#if SELECTED
return _SelectedBorderColor;
#elif HILITED
return _HilitedBorderColor;
#elif PATH_HILITE
return _PathHiliteBorderColor;
#else
return _BorderColor;
#endif
//float t = _Time[1] * 10.0f;
//float negOneToPosOne = sin(t);
//float zeroToOne = (negOneToPosOne + 1.0f) / 2.0f;
//float base = zeroToOne;
//float extra = 1.0f - base;
//return (base * _BorderColor) + (extra * _HilitedBorderColor);
}
ENDCG
}
}
}
Thanks
John Lawrie
7564261–936154–VideoAndShader.zip (7.22 MB)

