tonynogo

Demo 84 - Sprite dissolve

Jul 6th, 2017
6,150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/2D/Dissolve"
  2. {
  3.     Properties {
  4.         [PerRendererData] _MainTex ("Main texture", 2D) = "white" {}
  5.         _DissolveTex ("Dissolution texture", 2D) = "gray" {}
  6.         _Threshold ("Threshold", Range(0., 1.01)) = 0.
  7.     }
  8.  
  9.     SubShader {
  10.  
  11.         Tags { "Queue"="Transparent" }
  12.         Blend SrcAlpha OneMinusSrcAlpha
  13.  
  14.         Pass {
  15.            
  16.             CGPROGRAM
  17.             #pragma vertex vert
  18.             #pragma fragment frag
  19.  
  20.             #include "UnityCG.cginc"
  21.  
  22.             struct v2f {
  23.                 float4 pos : SV_POSITION;
  24.                 float2 uv : TEXCOORD0;
  25.             };
  26.            
  27.             sampler2D _MainTex;
  28.  
  29.             v2f vert(appdata_base v) {
  30.                 v2f o;
  31.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  32.                 o.uv = v.texcoord;
  33.                 return o;
  34.             }
  35.  
  36.             sampler2D _DissolveTex;
  37.             float _Threshold;
  38.  
  39.             fixed4 frag(v2f i) : SV_Target {
  40.                 float4 c = tex2D(_MainTex, i.uv);
  41.                 float val = tex2D(_DissolveTex, i.uv).r;
  42.  
  43.                 c.a *= step(_Threshold, val);
  44.                 return c;
  45.             }
  46.             ENDCG
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment