Advertisement
Guest User

Untitled

a guest
Oct 4th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2.  
  3. Shader "Custom/OutlineShader" {
  4.     Properties {
  5.         _MainTex ("Base (RGB)", 2D) = "white" {}
  6.         _Color ("Color", Color) = (1, 1, 1, 1)
  7.     }
  8.     SubShader {
  9.         Tags {"Queue"="Transparent" "RenderType"="Transparent"}
  10.         Cull Off
  11.         Blend One OneMinusSrcAlpha
  12.        
  13.         Pass {
  14.  
  15.             CGPROGRAM
  16.             #pragma vertex vert
  17.             #pragma fragment frag
  18.             #include "UnityCG.cginc"
  19.  
  20.             sampler2D _MainTex;
  21.  
  22.             struct v2f {
  23.                 float4 pos : SV_POSITION;
  24.                 half2 uv : TEXCOORD0;
  25.             };
  26.  
  27.             v2f vert(appdata_base v) {
  28.                 v2f o;
  29.                 o.pos = UnityObjectToClipPos(v.vertex);
  30.                 o.uv = v.texcoord;
  31.                 return o;
  32.             }
  33.  
  34.             fixed4 _Color;
  35.             float4 _MainTex_TexelSize;
  36.  
  37.             fixed4 frag(v2f i) : COLOR
  38.             {
  39.                 half4 c = tex2D(_MainTex, i.uv);
  40.                 c.rgb *= c.a;
  41.                 half4 outlineC = _Color;
  42.                 outlineC.a *= ceil(c.a);
  43.                 outlineC.rgb *= outlineC.a;
  44.  
  45.                 fixed alpha_up = tex2D(_MainTex, i.uv + fixed2(0, _MainTex_TexelSize.y)).a;
  46.                 fixed alpha_down = tex2D(_MainTex, i.uv - fixed2(0, _MainTex_TexelSize.y)).a;
  47.                 fixed alpha_right = tex2D(_MainTex, i.uv + fixed2(_MainTex_TexelSize.x, 0)).a;
  48.                 fixed alpha_left = tex2D(_MainTex, i.uv - fixed2(_MainTex_TexelSize.x, 0)).a;
  49.  
  50.                 return lerp(outlineC, c, ceil(alpha_up * alpha_down * alpha_right * alpha_left));
  51.             }  
  52.  
  53.             ENDCG
  54.         }
  55.     }
  56.     FallBack "Diffuse"
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement