Advertisement
tonynogo

Demo 19 - Outline 3D model

Jul 6th, 2017
22,980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Outline" {
  2.     Properties {
  3.         _MainTex ("MainTex", 2D) = "white" {}
  4.         _Outline ("_Outline", Range(0,0.1)) = 0
  5.         _OutlineColor ("Color", Color) = (1, 1, 1, 1)
  6.     }
  7.     SubShader {
  8.         Pass {
  9.             Tags { "RenderType"="Opaque" }
  10.             Cull Front
  11.  
  12.             CGPROGRAM
  13.  
  14.             #pragma vertex vert
  15.             #pragma fragment frag
  16.             #include "UnityCG.cginc"
  17.  
  18.             struct v2f {
  19.                 float4 pos : SV_POSITION;
  20.             };
  21.  
  22.             float _Outline;
  23.             float4 _OutlineColor;
  24.  
  25.             float4 vert(appdata_base v) : SV_POSITION {
  26.                 v2f o;
  27.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  28.                 float3 normal = mul((float3x3) UNITY_MATRIX_MV, v.normal);
  29.                 normal.x *= UNITY_MATRIX_P[0][0];
  30.                 normal.y *= UNITY_MATRIX_P[1][1];
  31.                 o.pos.xy += normal.xy * _Outline;
  32.                 return o.pos;
  33.             }
  34.  
  35.             half4 frag(v2f i) : COLOR {
  36.                 return _OutlineColor;
  37.             }
  38.  
  39.             ENDCG
  40.         }
  41.  
  42.         CGPROGRAM
  43.         #pragma surface surf Lambert
  44.  
  45.         sampler2D _MainTex;
  46.  
  47.         struct Input {
  48.             float2 uv_MainTex;
  49.         };
  50.  
  51.         void surf(Input IN, inout SurfaceOutput o) {
  52.             o.Albedo = tex2D(_MainTex, IN.uv_MainTex);
  53.         }
  54.  
  55.         ENDCG
  56.     }
  57.     FallBack "Diffuse"
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement