Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
  2.  
  3. Shader "Custom/Dissolve"
  4. {
  5.     Properties
  6.     {
  7.         _Color ("Color", COLOR)  = (0, 0, 0, 0)
  8.         _DissolveMap ("DissolveMap", 2D) = "white" {}
  9.         _Slice ("Slice", Range (0, 1)) = 0
  10.         _SliceColor ("SliceColor", COLOR) = (1, 1, 1, 1)
  11.     }
  12.     SubShader
  13.     {
  14.         Tags {
  15.             "RenderType"="Opaque"
  16.             "LightMode"="ForwardBase"
  17.         }
  18.  
  19.         Cull Off
  20.  
  21.         Pass
  22.         {
  23.             CGPROGRAM
  24.             #pragma vertex vert
  25.             #pragma fragment frag
  26.            
  27.             #include "UnityCG.cginc"
  28.  
  29.             // user difined
  30.             uniform float4 _Color;
  31.             uniform sampler2D _DissolveMap;
  32.             uniform float4 _DissolveMap_ST;
  33.             uniform float _Slice;
  34.             uniform float4 _SliceColor;
  35.  
  36.             // unity defined
  37.             uniform float4 _LightColor0;
  38.  
  39.             struct appdata
  40.             {
  41.                 float4 vertex : POSITION;
  42.                 float3 normal : NORMAL;
  43.                 float2 uv : TEXCOORD0;
  44.             };
  45.  
  46.             struct v2f
  47.             {
  48.                 float4 vertex : SV_POSITION;
  49.                 float3 normal : TEXCOORD0;
  50.                 float3 wVertex : TEXCOORD1;
  51.                 float2 uv : TEXCOORD2;
  52.             };
  53.            
  54.             v2f vert (appdata v)
  55.             {
  56.                 v2f o;
  57.  
  58.                 o.normal = v.normal;
  59.  
  60.                 //o.wVertex = UnityObjectToWorldDir (v.vertex);
  61.                 o.wVertex = v.vertex;
  62.  
  63.                 o.uv = v.uv;
  64.                 o.vertex = UnityObjectToClipPos(v.vertex);
  65.                 return o;
  66.             }
  67.            
  68.             fixed4 frag (v2f i) : SV_Target
  69.             {
  70.                 float3 normalWorld = UnityObjectToWorldNormal (i.normal);
  71.                 float3 lightDirection = normalize (_WorldSpaceLightPos0.xyz); // it's inverted light direction, or "direction towards the light" in other words
  72.                 float3 diffuseReflection = _LightColor0.rgb * saturate ( dot (normalWorld, lightDirection) );
  73.  
  74.                 float dissolveMap = tex2D (_DissolveMap, _DissolveMap_ST.xy * i.uv.xy + _DissolveMap_ST.zw).r;
  75.  
  76.                 float slice = dissolveMap - _Slice;
  77.                 float4 edge = _SliceColor * step (slice, 0.02);
  78.                 clip (slice);
  79.  
  80.  
  81.  
  82.                 return float4 (_Color * (diffuseReflection + UNITY_LIGHTMODEL_AMBIENT.rgb), 1.0) + edge;
  83.             }
  84.             ENDCG
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement