Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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:

alt text

when flashed:

alt text

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
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Derek-Wong · Apr 04, 2015 at 02:10 PM 0
Share

need help pls some shader expert!

avatar image tanoshimi · Apr 04, 2015 at 06:06 PM 0
Share

Please post the shader source, not the compiled shader.

avatar image Derek-Wong · Apr 04, 2015 at 06:35 PM 0
Share

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
          }
      }
  }
  
avatar image tanoshimi · Apr 04, 2015 at 07:04 PM 0
Share

Yes - that's the source. And what values are you passing for the _FlashColor and _FlashAmount when your flash goes off?

avatar image Derek-Wong · Apr 04, 2015 at 09:21 PM 0
Share

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╮(╯_╰)╭

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sprite not visible from behind 0 Answers

Sprites consisting of two packed textures 0 Answers

Allow 2D sprite to receive light from any direction and show on both sides 0 Answers

Replacing Sprites/Default shader 2 Answers

Make Sprite-Diffuse shader work on mesh renderer? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges