So, i tried a different approach. I'trying to draw directly on the tileset shader.
Right now i'm trying to draw a filled circle with a border on the map.
So far it's working, except that i am not able to modify my shader variables and i really don't know why
Here is the TilesetCutoutShader with the modification i added:
Shader "Custom/TilesetCutoutShaderCircleOnMap" {
Properties
{
_Color("Main Color", Color) = (1,1,1,1)
_MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
_OverlayBackTex("Overlay Back Texture", 2D) = "black" {}
_OverlayBackAlpha("Overlay Back Alpha", Range(0, 1)) = 1
_TrafficTex("Traffic Texture", 2D) = "black" {}
_OverlayFrontTex("Overlay Front Texture", 2D) = "black" {}
_OverlayFrontAlpha("Overlay Front Alpha", Range(0, 1)) = 1
//------------------------------------------------- DRAW A CIRCLE:
_BorderColor("Border Color", Color) = (0, 0, 0,1)
_FillColor("Fill Color",Color) = (1,1,1,1)
_Center("Center", Vector) = (0,0,0,0)
_Radius("Radius", Range(0, 1000)) = 500
_Border("Border", Range(0, 100)) = 10
}
SubShader
{
Tags {"Queue" = "AlphaTest-300" "IgnoreProjector" = "False" "RenderType" = "TransparentCutout"}
LOD 200
CGPROGRAM
#pragma surface surf Lambert alphatest:_Cutoff
sampler2D _MainTex;
sampler2D _OverlayBackTex;
half _OverlayBackAlpha;
sampler2D _TrafficTex;
sampler2D _OverlayFrontTex;
half _OverlayFrontAlpha;
fixed4 _Color;
//------------------------------------------------- DRAW A CIRCLE:
fixed4 _BorderColor;
fixed4 _FillColor;
float3 _Center;
float _Border;
float _Radius;
struct Input
{
float2 uv_MainTex;
float2 uv_OverlayBackTex;
float2 uv_TrafficTex;
float2 uv_OverlayFrontTex;
//------------------------------------------------- DRAW A CIRCLE:
float3 worldPos;
};
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
fixed4 t = tex2D(_OverlayBackTex, IN.uv_OverlayBackTex);
fixed3 ct = lerp(c.rgb, t.rgb, t.a * _OverlayBackAlpha);
t = tex2D(_TrafficTex, IN.uv_TrafficTex);
ct = lerp(ct, t.rgb, t.a);
t = tex2D(_OverlayFrontTex, IN.uv_OverlayFrontTex);
ct = lerp(ct, t.rgb, t.a * _OverlayFrontAlpha);
ct = ct * _Color;
o.Albedo = ct;
o.Alpha = c.a * _Color.a;
//------------------------------------------------- DRAW A CIRCLE:
float dist = distance(_Center, IN.worldPos);
if (dist < _Radius)
o.Albedo = lerp(ct, _FillColor, _FillColor.a);
else if (dist > _Radius && dist < (_Radius + _Border))
o.Albedo = lerp(ct, _BorderColor, _BorderColor.a);
}
ENDCG
}
Fallback "Transparent/Cutout/Diffuse"
}
Result :
Now, when i click on the map i try to do this :
//Keep trace of the last point clicked on the map
OnlineMapsControlBase.instance.GetCoords(out lastClickLng, out lastClickLat);
Vector3 p = OnlineMapsTileSetControl.instance.GetWorldPosition(lastClickLng, lastClickLat);
Debug.Log(p);
Shader.SetGlobalVector("_Center",p);
Shader.SetGlobalFloat("_Radius", 1000);
But it doesn't affect the shader. Am i missing something ?