Advertisement
evelynshilosky

OutlineFill - Part 5

Feb 25th, 2025
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. Shader "Custom/Outline Fill" {
  2.   Properties {
  3.     [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest", Float) = 0
  4.     _OutlineColor("Outline Color", Color) = (1, 1, 1, 1)
  5.     _OutlineWidth("Outline Width", Range(0, 10)) = 2
  6.   }
  7.  
  8.   SubShader {
  9.     Tags {
  10.       "Queue" = "Transparent+110"
  11.       "RenderType" = "Transparent"
  12.       "DisableBatching" = "True"
  13.     }
  14.  
  15.     Pass {
  16.       Name "Fill"
  17.       Cull Off
  18.       ZTest [_ZTest]
  19.       ZWrite Off
  20.       Blend SrcAlpha OneMinusSrcAlpha
  21.       ColorMask RGB
  22.  
  23.       Stencil {
  24.         Ref 1
  25.         Comp NotEqual
  26.       }
  27.  
  28.       CGPROGRAM
  29.       #include "UnityCG.cginc"
  30.  
  31.       #pragma vertex vert
  32.       #pragma fragment frag
  33.  
  34.       struct appdata {
  35.         float4 vertex : POSITION;
  36.         float3 normal : NORMAL;
  37.       };
  38.  
  39.       struct v2f {
  40.         float4 position : SV_POSITION;
  41.         fixed4 color : COLOR;
  42.       };
  43.  
  44.       uniform fixed4 _OutlineColor;
  45.       uniform float _OutlineWidth;
  46.  
  47.       v2f vert(appdata input) {
  48.         v2f output;
  49.         float3 viewPosition = UnityObjectToViewPos(input.vertex);
  50.         float3 viewNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, input.normal));
  51.  
  52.         output.position = UnityViewToClipPos(viewPosition + viewNormal * -viewPosition.z * _OutlineWidth / 1000.0);
  53.         output.color = _OutlineColor;
  54.         return output;
  55.       }
  56.  
  57.       fixed4 frag(v2f input) : SV_Target {
  58.         return input.color;
  59.       }
  60.       ENDCG
  61.     }
  62.   }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement