Advertisement
axoila

Pencil.shader

Feb 20th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Hidden/Pencil"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _EdgeColor ("Edge Color", Color) = (1,1,1,1)
  7.         _Noise ("Noise", 2D) = "white" {}
  8.         _NoiseCoefficient ("Intensity Noise Coefficient", Range(0, 1)) = 1
  9.     }
  10.     SubShader
  11.     {
  12.         // No culling or depth
  13.         Cull Off ZWrite Off ZTest Always
  14.         Blend SrcAlpha OneMinusSrcAlpha
  15.  
  16.         Pass
  17.         {
  18.             CGPROGRAM
  19.             #pragma vertex vert
  20.             #pragma fragment frag
  21.            
  22.             #include "UnityCG.cginc"
  23.  
  24.             struct appdata
  25.             {
  26.                 float4 vertex : POSITION;
  27.                 float2 uv : TEXCOORD0;
  28.             };
  29.  
  30.             struct v2f
  31.             {
  32.                 float2 uv : TEXCOORD0;
  33.                 float2 noise_uv : TEXCOORD1;
  34.                 float4 vertex : SV_POSITION;
  35.             };
  36.            
  37.             sampler2D _MainTex;
  38.  
  39.             float4 _Noise_ST;
  40.             sampler2D _Noise;
  41.  
  42.             float _NoiseCoefficient;
  43.  
  44.             fixed4 _EdgeColor;
  45.  
  46.             #define PI 3.14159265359
  47.  
  48.             v2f vert (appdata v)
  49.             {
  50.                 v2f o;
  51.                 o.vertex = UnityObjectToClipPos(v.vertex);
  52.                 o.uv = v.uv;
  53.                 o.noise_uv = TRANSFORM_TEX(v.uv, _Noise);
  54.                 return o;
  55.             }
  56.  
  57.             fixed4 frag (v2f i) : SV_Target
  58.             {
  59.  
  60.                 float intensity = tex2D(_MainTex, i.uv);
  61.                 float direction = intensity*2;
  62.                 intensity = 1-abs(intensity-0.5)*2;
  63.                 //return fixed4(intensity.xxx, 1);
  64.                 float offset = fmod(floor(_Time.y*17)*PI, 1);
  65.                 fixed noise = tex2D(_Noise, i.noise_uv + float2(offset, direction*_NoiseCoefficient)).r;
  66.                 //float center = smoothstep(1, 0.9, intensity);
  67.                 //intensity = smoothstep(0, 0.8, intensity);
  68.                 float border = smoothstep(0.2, 0.5, intensity+0.2 - noise);
  69.                 fixed4 col = float4(_EdgeColor.rgb, border);
  70.                 return col;
  71.             }
  72.             ENDCG
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement