Advertisement
Guest User

outline shader

a guest
Feb 5th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Basic Outline" {
  2.     Properties {
  3.         _Color ("Main Color", Color) = (.5,.5,.5,1)
  4.         _OutlineColor ("Outline Color", Color) = (0,0,0,1)
  5.         _Outline ("Outline width", Range (.002, 0.03)) = .005
  6.         _OutlineAlpha ("Outline alpha", Range (0, 1)) = 1
  7.         _MainTex ("Base (RGB)", 2D) = "white" { }
  8.     }
  9.    
  10.     CGINCLUDE
  11.     #include "UnityCG.cginc"
  12.    
  13.     struct appdata {
  14.         float4 vertex : POSITION;
  15.         float3 normal : NORMAL;
  16.     };
  17.  
  18.     struct v2f {
  19.         float4 pos : POSITION;
  20.         float4 color : COLOR;
  21.     };
  22.    
  23.     uniform float _Outline;
  24.     uniform float _OutlineAlpha;
  25.     uniform float4 _OutlineColor;
  26.    
  27.     v2f vert(appdata v) {
  28.         v2f o;
  29.         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  30.  
  31.         float3 norm   = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);
  32.         norm.z = -0.4;
  33.         float2 offset = TransformViewToProjection(norm.xy);
  34.        
  35.         o.pos.xy += offset * o.pos.z * _Outline;
  36.         //o.pos.xy += offset * _Outline;
  37.         //o.color = _OutlineColor;
  38.         return o;
  39.     }
  40.     ENDCG
  41.  
  42.     SubShader {
  43.         Tags { "RenderType"="Opaque" }
  44.         UsePass "Toon/Basic/BASE"
  45.         Pass {
  46.             Name "OUTLINE"
  47.             Tags { "LightMode" = "Always" }
  48.             Cull Front
  49.             ZWrite On
  50.             ColorMask RGB
  51.             Blend SrcAlpha OneMinusSrcAlpha
  52.  
  53.             CGPROGRAM
  54.             #pragma vertex vert
  55.             #pragma fragment frag
  56.             half4 frag(v2f i) :COLOR {
  57.                 half4 c = _OutlineColor;
  58.                 c.a = _OutlineAlpha;
  59.                 return c;
  60.                 //return i.color;
  61.             }
  62.             ENDCG
  63.         }
  64.     }
  65.    
  66.     SubShader {
  67.         Tags { "RenderType"="Opaque" }
  68.         UsePass "Toon/Basic/BASE"
  69.         Pass {
  70.             Name "OUTLINE"
  71.             Tags { "LightMode" = "Always" }
  72.             Cull Front
  73.             ZWrite On
  74.             ColorMask RGB
  75.             Blend SrcAlpha OneMinusSrcAlpha
  76.  
  77.             CGPROGRAM
  78.             #pragma vertex vert
  79.             #pragma exclude_renderers shaderonly
  80.             ENDCG
  81.             SetTexture [_MainTex] { combine primary }
  82.         }
  83.     }
  84.    
  85.     Fallback "Toon/Basic"
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement