Hyluss

shader outline test

Jul 24th, 2019
298
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. Shader "Custom/Outline"
  2. {
  3.     Properties{
  4.      _Color("Main Color", Color) = (0.5,0.5,0.5,1)
  5.      _MainTex("Texture", 2D) = "White" {}
  6.      _OutlineColor("Outline color", color) = (0,0,0,1)
  7.      _OutlineWidth("Outline width", Range(1.0,5.0)) = 1.01
  8.          _X("X",float) = 0 // shape center x
  9.          _Y("Y",float) = 0 // shape center y
  10.     }
  11.  
  12.  
  13.         SubShader{
  14.  
  15.          Pass{ //render the outline
  16.           ZWrite off
  17.  
  18.           CGPROGRAM
  19.           #pragma vertex vert
  20.           #pragma fragment frag
  21.  
  22.  
  23.          //starthere
  24.          struct appdata {
  25.             float4 vertex : POSITION;
  26.             float3 normal : NORMAL;
  27.           };
  28.  
  29.         struct v2f {
  30.              float4 pos : POSITION;
  31.              float3 normal : NORMAL;
  32.              float2 uvs : TEXCOORD0;
  33.         };
  34.  
  35.         float _OutlineWidth;
  36.         float4 _OutlineColor;
  37.         float _X;
  38.         float _Y;
  39.  
  40.         v2f vert(appdata v)
  41.         {
  42.             float xStartPos = v.vertex.x;
  43.             float yStartPos= v.vertex.y;
  44.  
  45.             float xOriginDiff = 0 - xStartPos;
  46.             float yOriginDiff = 0 - yStartPos;
  47.  
  48.             v.vertex.xyz *= _OutlineWidth;
  49.  
  50.             float xMultipliedOriginDiff = 0 - v.vertex.x;
  51.             float yMultipliedOriginDiff = 0 - v.vertex.y;
  52.  
  53.             float xDiff = abs(xMultipliedOriginDiff - xOriginDiff);
  54.             float yDiff = abs(yMultipliedOriginDiff - yOriginDiff);
  55.  
  56.            
  57.             // offset?
  58.             v.vertex.x += xDiff;
  59.             v.vertex.y += yDiff;
  60.             //
  61.        
  62.              v2f o;
  63.              o.pos = UnityObjectToClipPos(v.vertex);
  64.              return o;
  65.         };
  66.         //endhere
  67.  
  68.         half4 frag(v2f i) : COLOR
  69.         {
  70.             return _OutlineColor;
  71.         }
  72.         ENDCG
  73.        }
  74.  
  75.  
  76.        Pass
  77.        {
  78.         CGPROGRAM
  79.         #pragma vertex vert
  80.         #pragma fragment frag
  81.         // make fog work
  82.         #pragma multi_compile_fog
  83.  
  84.         #include "UnityCG.cginc"
  85.  
  86.         struct appdata
  87.         {
  88.          float4 vertex : POSITION;
  89.          float2 uv : TEXCOORD0;
  90.         };
  91.  
  92.         struct v2f
  93.         {
  94.          float2 uv : TEXCOORD0;
  95.          UNITY_FOG_COORDS(1)
  96.          float4 vertex : SV_POSITION;
  97.         };
  98.  
  99.         sampler2D _MainTex;
  100.         float4 _MainTex_ST;
  101.  
  102.         v2f vert(appdata v)
  103.         {
  104.          v2f o;
  105.          o.vertex = UnityObjectToClipPos(v.vertex);
  106.          o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  107.          UNITY_TRANSFER_FOG(o,o.vertex);
  108.          return o;
  109.         }
  110.  
  111.         fixed4 frag(v2f i) : SV_Target
  112.         {
  113.             // sample the texture
  114.             fixed4 col = tex2D(_MainTex, i.uv);
  115.         // apply fog
  116.         UNITY_APPLY_FOG(i.fogCoord, col);
  117.         return col;
  118.        }
  119.        ENDCG
  120.       }
  121.      }
  122.  
  123. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment