Hey guys, In a 2d game I'm working on I use a custom shader I found online to give the enemies and players a white flash effect when they get hit. The shader worked fine in Unity 4.6 but now In Unity 5 the shader acts weird. I've attached a screenshot of the problem. Code (CSharp): Shader "Sprites/Diffuse Flash" { Properties { [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} _SelfIllum ("Self Illumination",Range(0.0,1.0)) = 0.0 _FlashAmount ("Flash Amount",Range(0.0,1.0)) = 0.0 _Color ("Tint", Color) = (1,1,1,1) _FlashColor ("FlashColor", Color) = (1,1,1,1) [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" } Cull Off Lighting Off ZWrite Off Fog { Mode Off } Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma surface surf Lambert alpha vertex:vert #pragma multi_compile DUMMY PIXELSNAP_ON sampler2D _MainTex; fixed4 _Color; fixed4 _FlashColor; float _FlashAmount,_SelfIllum; struct Input { float2 uv_MainTex; fixed4 color; }; void vert (inout appdata_full v, out Input o) { #if defined(PIXELSNAP_ON) && !defined(SHADER_API_FLASH) v.vertex = UnityPixelSnap (v.vertex); #endif v.normal = float3(0,0,-1); UNITY_INITIALIZE_OUTPUT(Input, o); o.color = _Color; } void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color; o.Albedo = lerp(c.rgb,float3(_FlashColor.r,_FlashColor.g,_FlashColor.b),_FlashAmount); o.Emission = lerp(c.rgb,float3(_FlashColor.r,_FlashColor.g,_FlashColor.b),_FlashAmount) * _SelfIllum; o.Alpha = c.a; } ENDCG } Fallback "Transparent/VertexLit" } Here's the script. Is there anyone who could help me out?
I too am using a modified version of this shader and am having the same issue. If you manage to fix it, could you post it here? Thanks
Hi jakkovanhunen, I updated the line, based on your suggestion, to: Code (CSharp): o.Albedo = lerp(c.rgb,float3(_FlashColor.r,_FlashColor.g,_FlashColor.b),_FlashAmount) * c.a; This didn't fix the issue, unfortunately.
Ah, well it solved some shader problems for me that looked similar. Guess they were not similar after all.
In 5 there is different types of alpha mode in the shader, change this: #pragma surface surf Lambert alpha vertex:vert To this: #pragma surface surf Lambert alpha:blend vertex:vert It should fix it!