102 lines
3.0 KiB
Plaintext
102 lines
3.0 KiB
Plaintext
Shader "Bansonic/Sprite Dissolve"
|
|
{
|
|
Properties
|
|
{
|
|
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
|
|
_NoiseTex ("Noise Texture", 2D) = "white" {}
|
|
_Color ("Tint", Color) = (1,1,1,1)
|
|
_DissolveAmount ("Dissolve Amount", Range(0, 1)) = 0
|
|
_EdgeWidth ("Edge Width", Range(0.001, 0.5)) = 0.08
|
|
_EdgeColor ("Edge Color", Color) = (1,0.6,0.1,1)
|
|
_EdgeEmission ("Edge Emission", Range(0, 5)) = 1.5
|
|
_NoiseTiling ("Noise Tiling", Vector) = (1,1,0,0)
|
|
_NoiseOffset ("Noise Offset", Vector) = (0,0,0,0)
|
|
[MaterialToggle] PixelSnap ("Pixel Snap", Float) = 0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"Queue"="Transparent"
|
|
"IgnoreProjector"="True"
|
|
"RenderType"="Transparent"
|
|
"PreviewType"="Plane"
|
|
"CanUseSpriteAtlas"="True"
|
|
}
|
|
|
|
Cull Off
|
|
Lighting Off
|
|
ZWrite Off
|
|
Blend One OneMinusSrcAlpha
|
|
|
|
Pass
|
|
{
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma target 2.0
|
|
#pragma multi_compile _ 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;
|
|
float2 uv : TEXCOORD0;
|
|
float2 noiseUV : TEXCOORD1;
|
|
};
|
|
|
|
sampler2D _MainTex;
|
|
sampler2D _NoiseTex;
|
|
fixed4 _Color;
|
|
fixed4 _EdgeColor;
|
|
float _DissolveAmount;
|
|
float _EdgeWidth;
|
|
float _EdgeEmission;
|
|
float4 _NoiseTiling;
|
|
float4 _NoiseOffset;
|
|
|
|
v2f vert(appdata_t IN)
|
|
{
|
|
v2f OUT;
|
|
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
|
OUT.uv = IN.texcoord;
|
|
OUT.noiseUV = IN.texcoord * _NoiseTiling.xy + _NoiseOffset.xy;
|
|
OUT.color = IN.color * _Color;
|
|
|
|
#ifdef PIXELSNAP_ON
|
|
OUT.vertex = UnityPixelSnap(OUT.vertex);
|
|
#endif
|
|
|
|
return OUT;
|
|
}
|
|
|
|
fixed4 frag(v2f IN) : SV_Target
|
|
{
|
|
fixed4 baseCol = tex2D(_MainTex, IN.uv) * IN.color;
|
|
float noise = tex2D(_NoiseTex, IN.noiseUV).r;
|
|
float edgeStart = _DissolveAmount - _EdgeWidth;
|
|
|
|
clip(noise - _DissolveAmount);
|
|
|
|
float edgeMask = 1.0 - saturate((noise - edgeStart) / max(_EdgeWidth, 0.0001));
|
|
fixed3 edgeGlow = _EdgeColor.rgb * edgeMask * _EdgeEmission;
|
|
|
|
fixed4 col;
|
|
col.rgb = baseCol.rgb + edgeGlow;
|
|
col.a = baseCol.a;
|
|
return col;
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
}
|