Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/Outline Fill" {
- Properties {
- [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest", Float) = 0
- _OutlineColor("Outline Color", Color) = (1, 1, 1, 1)
- _OutlineWidth("Outline Width", Range(0, 10)) = 2
- }
- SubShader {
- Tags {
- "Queue" = "Transparent+110"
- "RenderType" = "Transparent"
- "DisableBatching" = "True"
- }
- Pass {
- Name "Fill"
- Cull Off
- ZTest [_ZTest]
- ZWrite Off
- Blend SrcAlpha OneMinusSrcAlpha
- ColorMask RGB
- Stencil {
- Ref 1
- Comp NotEqual
- }
- CGPROGRAM
- #include "UnityCG.cginc"
- #pragma vertex vert
- #pragma fragment frag
- struct appdata {
- float4 vertex : POSITION;
- float3 normal : NORMAL;
- };
- struct v2f {
- float4 position : SV_POSITION;
- fixed4 color : COLOR;
- };
- uniform fixed4 _OutlineColor;
- uniform float _OutlineWidth;
- v2f vert(appdata input) {
- v2f output;
- float3 viewPosition = UnityObjectToViewPos(input.vertex);
- float3 viewNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, input.normal));
- output.position = UnityViewToClipPos(viewPosition + viewNormal * -viewPosition.z * _OutlineWidth / 1000.0);
- output.color = _OutlineColor;
- return output;
- }
- fixed4 frag(v2f input) : SV_Target {
- return input.color;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement