Advertisement
tonynogo

Demo 44 - Burning paper

Jul 6th, 2017
8,617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/BurningPaper"
  2. {
  3.     Properties {
  4.         _MainTex ("Main texture", 2D) = "white" {}
  5.         _DissolveTex ("Dissolution texture", 2D) = "gray" {}
  6.         _Threshold ("Threshold", Range(0, 1.1)) = 0
  7.     }
  8.  
  9.     SubShader {
  10.  
  11.         Tags { "Queue"="Geometry" }
  12.  
  13.         Pass {
  14.            
  15.             CGPROGRAM
  16.             #pragma vertex vert
  17.             #pragma fragment frag
  18.  
  19.             #include "UnityCG.cginc"
  20.  
  21.             struct v2f {
  22.                 float4 pos : SV_POSITION;
  23.                 float2 uv : TEXCOORD0;
  24.             };
  25.            
  26.             sampler2D _MainTex;
  27.             float4 _MainTex_ST;
  28.  
  29.             v2f vert(appdata_base v) {
  30.                 v2f o;
  31.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  32.                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  33.                 return o;
  34.             }
  35.  
  36.             sampler2D _DissolveTex;
  37.             float _Threshold;
  38.  
  39.             fixed4 frag(v2f i) : SV_Target {
  40.                 fixed4 c = tex2D(_MainTex, i.uv);
  41.                 fixed val = 1 - tex2D(_DissolveTex, i.uv).r;
  42.                 if(val < _Threshold - 0.04)
  43.                 {
  44.                     discard;
  45.                 }
  46.  
  47.                 bool b = val < _Threshold;
  48.                 return lerp(c, c * fixed4(lerp(1, 0, 1 - saturate(abs(_Threshold - val) / 0.04)), 0, 0, 1), b);
  49.             }
  50.  
  51.             ENDCG
  52.  
  53.         }
  54.  
  55.     }
  56.     FallBack "Diffuse"
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement