- Home /
Fog of War overlay for overhead map.
Having used the tutorial by Sergey Taraban I have manage to create a working overlay for an overhead map. What I have achieved is as the player explores the world, the area on the map is revealed. I am hoping to refine the shader but lack the understanding for pragma. What I intend to have happen is instead of applying a color to the "Fog of War area" (black portion) apply a texture instead. The current shader code is as follows, the Tutorial can be found at https://www.youtube.com/watch?v=PNAvNeOTnSE. Any help would be appreciated.
Shader "Custom/FogOfWarMask" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _BlurPower("BlurPower", float) = 0.002 } SubShader{ Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" } Blend SrcAlpha OneMinusSrcAlpha //Lighting off //LOD 200 CGPROGRAM #pragma surface surf Lambert alpha:fade #pragma target 3.0 fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, float aten) { fixed4 color; color.rgb = s.Albedo; color.a = s.Alpha; return color; }
fixed4 _Color; sampler2D _MainTex; float _BlurPower;
struct Input { float2 uv_MainTex; };
void surf(Input IN, inout SurfaceOutput o) { half4 baseColor1 = tex2D(_MainTex, IN.uv_MainTex + float2(-_BlurPower, 0)); half4 baseColor2 = tex2D(_MainTex, IN.uv_MainTex + float2(0, -_BlurPower)); half4 baseColor3 = tex2D(_MainTex, IN.uv_MainTex + float2(_BlurPower, 0)); half4 baseColor4 = tex2D(_MainTex, IN.uv_MainTex + float2(0, _BlurPower)); half4 baseColor = 0.25 (baseColor1 + baseColor2 + baseColor3 + baseColor4); //o.Albedo = baseColor.rgb; o.Albedo = _Color.rgb baseColor.b; o.Alpha = _Color.a - baseColor.g; } ENDCG } }
Answer by HappyGoLucky · Oct 20, 2017 at 08:52 PM
Figured it out by combining two shaders together. The end result is as follows.
Shader "Custom/FogOfWarMask" { Properties{ _Color("Color", Color) = (1,1,1,1) _MainTex("Albedo (RGB)", 2D) = "white" {} _BlurPower("BlurPower", float) = 0.002 _PaintTex("Paint Texture (RGBA)", 2D) = "white" {} _BlendAmount("Blend Amount", Range(0.0, 1.0)) = 1.0 } SubShader{ Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" } Blend SrcAlpha OneMinusSrcAlpha //Lighting off //LOD 200
CGPROGRAM
pragma surface surf Lambert alpha:fade
pragma target 3.0
fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, float aten) {
fixed4 color;
color.rgb = s.Albedo;
color.a = s.Alpha;
return color;
}
float _BlurPower;
fixed4 _Color;
sampler2D _MainTex;
sampler2D _PaintTex;
fixed _BlendAmount;
struct Input
{
float2 uv_MainTex;
float2 uv_PaintTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
half4 baseColor1 = tex2D(_MainTex, IN.uv_MainTex + float2(-_BlurPower, 0));
half4 baseColor2 = tex2D(_MainTex, IN.uv_MainTex + float2(0, -_BlurPower));
half4 baseColor3 = tex2D(_MainTex, IN.uv_MainTex + float2(_BlurPower, 0));
half4 baseColor4 = tex2D(_MainTex, IN.uv_MainTex + float2(0, _BlurPower));
half4 baseColor = 0.25 * (baseColor1 + baseColor2 + baseColor3 + baseColor4);
fixed4 paint = tex2D(_PaintTex, IN.uv_MainTex);
o.Albedo = baseColor.rgb;
o.Albedo = lerp((_Color.rgb * baseColor.b), paint, _Color.a * _BlendAmount);
o.Alpha = _Color.a - baseColor.g;
}
ENDCG
}
}
Hey thanks so much, I'm so glad I stumbled across this. Spent the last 4.5 hours trying to work out why $$anonymous$$e was working after trying the same tutorial. Ended up just needing to add alpha:fade
to the end of the`#pragma` line.
Your answer
Follow this Question
Related Questions
shadertoy to unity,Shadertoy to unity 0 Answers
How can i combine shaders? 0 Answers
3 Color linear gradient shader 1 Answer
Prevent overlapping UI image 0 Answers
Get shadowmap in HDRP with commandBuffer 0 Answers