I have a question that I want make enemy cone sight.
I found an approximate solution.But it’s Unity.
its:True Cone of Sight? Commandos - Unity Answers
So,Can someone help me implement it in UE4? I dont know shader.
Shader Code:
struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; }
struct v2f { float4 uvShadow : TEXCOORD0; float4 uvFalloff : TEXCOORD1; float4 pos : SV_POSITION; float3 norm : NORMAL; };
v2f vert (appdata i) { v2f o; o.pos = mul (UNITY_MATRIX_MVP, i.vertex); o.uvShadow = mul (_Projector, i.vertex); o.uvFalloff = mul (_ProjectorClip, i.vertex); o.normal = i.normal; return o; }
`fixed4 frag (v2f i) : SV_Target
{
fixed4 texS = tex2Dproj (_ShadowTex, UNITY_PROJ_COORD(i.uvShadow));
texS.a = 1.0-texS.a;
fixed4 texF = tex2Dproj (_FalloffTex, UNITY_PROJ_COORD(i.uvFalloff));
fixed4 res;
// assume Y is up
if(dot(i.normal, float3(0,1,0)) >= 0.9) {
res = lerp(fixed4(1,1,1,0), texS, texF.a);
} else {
res = texS;
}
return res;
}`