Advertisement
Pufferfiz

Dissolve Shader With Transparency

Feb 2nd, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. Shader "DissolveShader"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Color (RGB) Alpha (A)", 2D) = "white"
  6.        
  7.         _DissolveMap("Dissolve Shape", 2D) = "white"{}
  8.        
  9.         _DissolveVal("Dissolve Value", Range(-0.2, 1.2)) = 1.2
  10.        
  11.         _LineWidth("Line Width", Range(0.0, 0.2)) = 0.1
  12.        
  13.         _LineColor("Line Color", Color) = (1.0, 1.0, 1.0, 1.0)
  14.     }
  15.     SubShader
  16.     {
  17.         Tags { "Queue"="Transparent" "RenderType"="Transparent" }
  18.         Blend SrcAlpha OneMinusSrcAlpha
  19.        
  20.         CGPROGRAM
  21.         #pragma surface surf Lambert alpha
  22.        
  23.         sampler2D _MainTex;
  24.         sampler2D _DissolveMap;
  25.        
  26.         float4 _LineColor;
  27.         float _DissolveVal;
  28.         float _LineWidth;
  29.        
  30.         struct Input
  31.         {
  32.                 half2 uv_MainTex;
  33.                 half2 uv_DissolveMap;
  34.         };
  35.  
  36.         void surf (Input IN, inout SurfaceOutput o)
  37.         {
  38.             o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
  39.  
  40.             half4 dissolve = tex2D(_DissolveMap, IN.uv_DissolveMap);
  41.            
  42.             half4 clear = half4(0.0);
  43.  
  44.             int isClear = int(dissolve.r - (_DissolveVal + _LineWidth) + 0.99);
  45.             int isAtLeastLine = int(dissolve.r - (_DissolveVal) + 0.99);
  46.  
  47.             half4 altCol = lerp(_LineColor, clear, isClear);
  48.  
  49.             o.Albedo = lerp(o.Albedo, altCol, isAtLeastLine);
  50.            
  51.             o.Alpha = lerp(1.0, 0.0, isClear);
  52.             o.Alpha =  o.Alpha * tex2D (_MainTex, IN.uv_MainTex).a;
  53.         }
  54.         ENDCG
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement