Advertisement
Gabriel1375

Untitled

Oct 4th, 2021
2,329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Unlit/InnerSpriteOutline HLSL"
  2. {
  3.     Properties
  4.     {
  5.         _Color("Tint", Color) = (0, 0, 0, 1)
  6.         _MainTex("Texture", 2D) = "white" {}
  7.         _OutlineColor("Outline Color", Color) = (1,1,1,1)
  8.     }
  9.         SubShader
  10.         {
  11.             Tags
  12.             {
  13.                 "Queue" = "Transparent"
  14.             }
  15.  
  16.             Blend SrcAlpha OneMinusSrcAlpha
  17.  
  18.             Pass
  19.             {
  20.                 ZTest Off
  21.                 Blend SrcAlpha OneMinusSrcAlpha
  22.                 CGPROGRAM
  23.                 #pragma vertex vert
  24.                 #pragma fragment frag
  25.  
  26.                 #include "UnityCG.cginc"
  27.  
  28.                 struct appdata
  29.                 {
  30.                     float4 vertex : POSITION;
  31.                     float2 uv : TEXCOORD0;
  32.                     fixed4 color : COLOR;
  33.                 };
  34.  
  35.                 struct v2f
  36.                 {
  37.                     float2 uv : TEXCOORD0;
  38.                     float4 vertex : SV_POSITION;
  39.                     float4 color : COLOR;
  40.                 };
  41.  
  42.                 sampler2D _MainTex;
  43.                 float4 _MainTex_ST;
  44.                 float4 _MainTex_TexelSize;
  45.  
  46.                 fixed4 _Color;
  47.                 fixed4 _OutlineColor;
  48.  
  49.                 v2f vert(appdata v)
  50.                 {
  51.                     v2f o;
  52.                     o.vertex = UnityObjectToClipPos(v.vertex);
  53.                     o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  54.                     o.color = v.color;
  55.                     return o;
  56.                 }
  57.  
  58.                 fixed4 frag(v2f i) : SV_Target
  59.                 {
  60.                     fixed4 col = tex2D(_MainTex, i.uv);
  61.                     col *= _Color;
  62.                     col *= i.color;
  63.  
  64.                     fixed leftPixel = tex2D(_MainTex, i.uv + float2(-_MainTex_TexelSize.x, 0)).a;
  65.                     fixed upPixel = tex2D(_MainTex, i.uv + float2(0, _MainTex_TexelSize.y)).a;
  66.                     fixed rightPixel = tex2D(_MainTex, i.uv + float2(_MainTex_TexelSize.x, 0)).a;
  67.                     fixed bottomPixel = tex2D(_MainTex, i.uv + float2(0, -_MainTex_TexelSize.y)).a;
  68.  
  69.                     fixed outline = (1 - leftPixel * upPixel * rightPixel * bottomPixel) * col.a;
  70.  
  71.                     return lerp(col, _OutlineColor, outline);
  72.                 }
  73.                 ENDCG
  74.             }
  75.         }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement