- Home /
Question by
Derek-Wong · Apr 04, 2015 at 02:44 AM ·
shadersprite
2D Sprite Flash Shader - unwanted outline
Dear all,
I am trying to flash my sprite to completely white to make a hitting effect on monster. I have searched on some post and found that a really good shader to get this effect.
However, I found that this shader will give a small outline to the sprite in Unity 5, please help to figure what is the problem.
I am an idiot of shader :( please help.
the outline:
when flashed:
The shader:
// Compiled shader for Android, uncompressed size: 3.5KB
// Skipping shader variants that would not be included into build of current scene.
Shader "Sprites/DefaultColorFlash" {
Properties {
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" { }
_Color ("Tint", Color) = (1,1,1,1)
_FlashColor ("Flash Color", Color) = (1,1,1,1)
_FlashAmount ("Flash Amount", Range(0,1)) = 0
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
}
SubShader {
Tags { "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="true" }
// Stats for Vertex shader:
// gles : 3 math, 1 texture
Pass {
Tags { "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="true" }
ZWrite Off
Cull Off
Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
GpuProgramID 31062
Program "vp" {
SubProgram "gles " {
// Stats: 3 math, 1 textures
Keywords { "DUMMY" }
"!!GLES
#ifdef VERTEX
attribute vec4 _glesVertex;
attribute vec4 _glesColor;
attribute vec4 _glesMultiTexCoord0;
uniform highp mat4 glstate_matrix_mvp;
uniform lowp vec4 _Color;
varying lowp vec4 xlv_COLOR;
varying mediump vec2 xlv_TEXCOORD0;
void main ()
{
highp vec2 tmpvar_1;
tmpvar_1 = _glesMultiTexCoord0.xy;
lowp vec4 tmpvar_2;
mediump vec2 tmpvar_3;
tmpvar_3 = tmpvar_1;
highp vec4 tmpvar_4;
tmpvar_4 = (_glesColor * _Color);
tmpvar_2 = tmpvar_4;
gl_Position = (glstate_matrix_mvp * _glesVertex);
xlv_COLOR = tmpvar_2;
xlv_TEXCOORD0 = tmpvar_3;
}
#endif
#ifdef FRAGMENT
uniform lowp vec4 _FlashColor;
uniform highp float _FlashAmount;
uniform sampler2D _MainTex;
varying lowp vec4 xlv_COLOR;
varying mediump vec2 xlv_TEXCOORD0;
void main ()
{
lowp vec4 c_1;
lowp vec4 tmpvar_2;
tmpvar_2 = (texture2D (_MainTex, xlv_TEXCOORD0) * xlv_COLOR);
c_1.w = tmpvar_2.w;
highp vec3 tmpvar_3;
tmpvar_3 = mix (tmpvar_2.xyz, _FlashColor.xyz, vec3(_FlashAmount));
c_1.xyz = tmpvar_3;
c_1.xyz = (c_1.xyz * tmpvar_2.w);
gl_FragData[0] = c_1;
}
#endif"
}
SubProgram "gles " {
// Stats: 3 math, 1 textures
Keywords { "PIXELSNAP_ON" }
"!!GLES
#ifdef VERTEX
attribute vec4 _glesVertex;
attribute vec4 _glesColor;
attribute vec4 _glesMultiTexCoord0;
uniform highp vec4 _ScreenParams;
uniform highp mat4 glstate_matrix_mvp;
uniform lowp vec4 _Color;
varying lowp vec4 xlv_COLOR;fixed
varying mediump vec2 xlv_TEXCOORD0;
void main ()
{
highp vec2 tmpvar_1;
tmpvar_1 = _glesMultiTexCoord0.xy;
lowp vec4 tmpvar_2;
mediump vec2 tmpvar_3;
highp vec4 tmpvar_4;
tmpvar_4 = (glstate_matrix_mvp * _glesVertex);
tmpvar_3 = tmpvar_1;
highp vec4 tmpvar_5;
tmpvar_5 = (_glesColor * _Color);
tmpvar_2 = tmpvar_5;
highp vec4 pos_6;
pos_6.zw = tmpvar_4.zw;
highp vec2 tmpvar_7;
tmpvar_7 = (_ScreenParams.xy * 0.5);
pos_6.xy = ((floor(
(((tmpvar_4.xy / tmpvar_4.w) * tmpvar_7) + vec2(0.5, 0.5))
) / tmpvar_7) * tmpvar_4.w);
gl_Position = pos_6;
xlv_COLOR = tmpvar_2;
xlv_TEXCOORD0 = tmpvar_3;
}
#endif
#ifdef FRAGMENT
uniform lowp vec4 _FlashColor;
uniform highp float _FlashAmount;
uniform sampler2D _MainTex;
varying lowp vec4 xlv_COLOR;
varying mediump vec2 xlv_TEXCOORD0;
void main ()
{
lowp vec4 c_1;
lowp vec4 tmpvar_2;
tmpvar_2 = (texture2D (_MainTex, xlv_TEXCOORD0) * xlv_COLOR);
c_1.w = tmpvar_2.w;
highp vec3 tmpvar_3;
tmpvar_3 = mix (tmpvar_2.xyz, _FlashColor.xyz, vec3(_FlashAmount));
c_1.xyz = tmpvar_3;
c_1.xyz = (c_1.xyz * tmpvar_2.w);
gl_FragData[0] = c_1;
}
#endif"
}
}
Program "fp" {
SubProgram "gles " {
Keywords { "DUMMY" }
"!!GLES"
}
SubProgram "gles " {
Keywords { "PIXELSNAP_ON" }
"!!GLES"
}
}
}
}
}
outlined.jpg
(95.2 kB)
flash.jpg
(74.0 kB)
Comment
Please post the shader source, not the compiled shader.
Is this the source?
Shader "Sprites/DefaultColorFlash"
{
Properties
{
[PerRendererData] _$$anonymous$$ainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_FlashColor ("Flash Color", Color) = (1,1,1,1)
_FlashAmount ("Flash Amount",Range(0.0,1.0)) = 0.0
[$$anonymous$$aterialToggle] PixelSnap ("Pixel snap", Float) = 0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ZWrite Off
Fog { $$anonymous$$ode Off }
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
Pass
{
CGPROGRA$$anonymous$$
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile DU$$anonymous$$$$anonymous$$Y PIXELSNAP_ON
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
fixed4 _Color;
fixed4 _FlashColor;
float _FlashAmount;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = mul(UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, IN.vertex);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color;
#ifdef PIXELSNAP_ON
OUT.vertex = UnityPixelSnap (OUT.vertex);
#endif
return OUT;
}
sampler2D _$$anonymous$$ainTex;
fixed4 frag(v2f IN) : COLOR
{
fixed4 c = tex2D(_$$anonymous$$ainTex, IN.texcoord) * IN.color;
c.rgb = lerp(c.rgb,_FlashColor.rgb,_FlashAmount);
c.rgb *= c.a;
return c;
}
ENDCG
}
}
}
Yes - that's the source. And what values are you passing for the _FlashColor and _FlashAmount when your flash goes off?
i pass white color and from 0 to 1 for the amount. no matter what was the flash amount, the sprite still have the unwanted outline╮(╯_╰)╭