Advertisement
Guest User

Untitled

a guest
Apr 9th, 2019
81
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 "Outlined/Silhouette Only" {
  4.     Properties{
  5.         _OutlineColor("Outline Color", Color) = (0,0,0,1)
  6.         _Outline("Outline width", Range(0.0, 0.1)) = .005
  7.     }
  8.  
  9. CGINCLUDE
  10. #include "UnityCG.cginc"
  11.  
  12.     struct appdata {
  13.         float4 vertex : POSITION;
  14.         float3 normal : NORMAL;
  15.     };
  16.  
  17.     struct v2f {
  18.         float4 pos : POSITION;
  19.         float4 color : COLOR;
  20.     };
  21.  
  22.     uniform float _Outline;
  23.     uniform float4 _OutlineColor;
  24.  
  25.     v2f vert(appdata v) {
  26.         // just make a copy of incoming vertex data but scaled according to normal direction
  27.         v2f o;
  28.         o.pos = UnityObjectToClipPos(v.vertex);
  29.  
  30.         float3 norm = mul((float3x3)UNITY_MATRIX_IT_MV, v.normal);
  31.         float2 offset = TransformViewToProjection(norm.xy);
  32.  
  33.         o.pos.xy += offset * o.pos.z * _Outline;
  34.         o.color = _OutlineColor;
  35.         return o;
  36.     }
  37.     ENDCG
  38.  
  39.         SubShader{
  40.             Tags { "Queue" = "Transparent" }
  41.  
  42.             Pass {
  43.                 Name "BASE"
  44.                 Cull Back
  45.                 Blend Zero One
  46.  
  47.         // uncomment this to hide inner details:
  48.         //Offset -8, -8
  49.  
  50.         SetTexture[_OutlineColor] {
  51.             ConstantColor(0,0,0,0)
  52.             Combine constant
  53.         }
  54.     }
  55.  
  56.         // note that a vertex shader is specified here but it's using the one above
  57.         Pass {
  58.             Name "OUTLINE"
  59.             Tags { "LightMode" = "Always" }
  60.             Cull Front
  61.  
  62.         // you can choose what kind of blending mode you want for the outline
  63.         //Blend SrcAlpha OneMinusSrcAlpha // Normal
  64.         //Blend One One // Additive
  65.         Blend One OneMinusDstColor // Soft Additive
  66.         //Blend DstColor Zero // Multiplicative
  67.         //Blend DstColor SrcColor // 2x Multiplicative
  68.  
  69. CGPROGRAM
  70. #pragma vertex vert
  71. #pragma fragment frag
  72.  
  73. half4 frag(v2f i) :COLOR {
  74.     return i.color;
  75. }
  76. ENDCG
  77.         }
  78.  
  79.  
  80.     }
  81.  
  82.         Fallback "Diffuse"
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement