Yesterday I had implemented Fog of war for my RTS game. All was working fine last night before I went to bed, I checked it scene by scene and ran through loads of tests to make sure it was working and all was good.
But today, when I try and run the game, it loads the main menu, but when it tries to load the first level, unity crashes and doesn't give me a reason.
I tried going through code and game objects until I found that if I removed the custom shader attached to the terrain I was using to create fog over the map, it would stop crashing unity and continue running the game, however I reattached it and it ran fine again with the fog of war working again, but as soon as i closed unity and opened it again, the same problem occurred with crashing loading the first level.
I am unsure if it is the shader or the code for it thats causing the problem. I have little experience with shaders but if anyone can have a look at the code for it and tell me if anything looks wrong with it I would be very greatful.
Shader "Fog Of War/Terrain" {
Properties {
_FOWTex ("Detail", 2D) = "gray" {}
// Splat Map Control Texture
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
// used in fallback on old cards & base map
// [HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
// [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "RenderType"="Opaque"
"SplatCount" = "4"
}
CGPROGRAM
#pragma surface surf Lambert nolightmap
struct Input {
float2 uv_FOWTex;
float2 uv_Control : TEXCOORD0;
float2 uv_Splat0 : TEXCOORD1;
float2 uv_Splat1 : TEXCOORD2;
float2 uv_Splat2 : TEXCOORD3;
float2 uv_Splat3 : TEXCOORD4;
};
sampler2D _Control, _FOWTex;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
void surf (Input IN, inout SurfaceOutput o) {
fixed4 splat_control = tex2D (_Control, IN.uv_Control);
fixed3 col;
col = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
o.Albedo = col;
fixed3 c = tex2D (_FOWTex, IN.uv_FOWTex).aaa;
c = 1-c;
o.Albedo *= c;
}
ENDCG
}
FallBack off
}