Shader "Project/InteractOutline" { Properties { _OutlineColor ("Outline Color", Color) = (0,1,0,1) _OutlineWidth ("Outline Width", Float) = 0.02 _Emission ("Emission", Float) = 1 _InnerWidthScale ("Inner Width Scale", Float) = 0.6 _OuterWidthScale ("Outer Width Scale", Float) = 1.2 _InnerAlpha ("Inner Alpha", Range(0, 1)) = 1 _OuterAlpha ("Outer Alpha", Range(0, 1)) = 0 } SubShader { Tags { "RenderPipeline"="UniversalPipeline" "Queue"="Transparent" "RenderType"="Transparent" } Pass { Name "OutlineLayer3" Tags { "LightMode"="UniversalForward" } Cull Front ZWrite Off ZTest LEqual Blend SrcAlpha One HLSLPROGRAM #pragma vertex vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" CBUFFER_START(UnityPerMaterial) float4 _OutlineColor; float _OutlineWidth; float _Emission; float _InnerWidthScale; float _OuterWidthScale; float _InnerAlpha; float _OuterAlpha; CBUFFER_END struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; }; struct Varyings { float4 positionHCS : SV_POSITION; }; Varyings vert (Attributes input) { Varyings output; float t = 1.0; float widthScale = lerp(_InnerWidthScale, _OuterWidthScale, t); float3 posOS = input.positionOS.xyz + input.normalOS * (_OutlineWidth * widthScale); output.positionHCS = TransformObjectToHClip(posOS); return output; } half4 frag (Varyings input) : SV_Target { float t = 1.0; float alpha = lerp(_InnerAlpha, _OuterAlpha, t); return half4(_OutlineColor.rgb * _Emission, _OutlineColor.a * alpha); } ENDHLSL } Pass { Name "OutlineLayer0" Tags { "LightMode"="UniversalForward" } Cull Front ZWrite Off ZTest LEqual Blend SrcAlpha One HLSLPROGRAM #pragma vertex vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" CBUFFER_START(UnityPerMaterial) float4 _OutlineColor; float _OutlineWidth; float _Emission; float _InnerWidthScale; float _OuterWidthScale; float _InnerAlpha; float _OuterAlpha; CBUFFER_END struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; }; struct Varyings { float4 positionHCS : SV_POSITION; }; Varyings vert (Attributes input) { Varyings output; float t = 0.0; float widthScale = lerp(_InnerWidthScale, _OuterWidthScale, t); float3 posOS = input.positionOS.xyz + input.normalOS * (_OutlineWidth * widthScale); output.positionHCS = TransformObjectToHClip(posOS); return output; } half4 frag (Varyings input) : SV_Target { float t = 0.0; float alpha = lerp(_InnerAlpha, _OuterAlpha, t); return half4(_OutlineColor.rgb * _Emission, _OutlineColor.a * alpha); } ENDHLSL } Pass { Name "OutlineLayer1" Tags { "LightMode"="UniversalForward" } Cull Front ZWrite Off ZTest LEqual Blend SrcAlpha One HLSLPROGRAM #pragma vertex vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" CBUFFER_START(UnityPerMaterial) float4 _OutlineColor; float _OutlineWidth; float _Emission; float _InnerWidthScale; float _OuterWidthScale; float _InnerAlpha; float _OuterAlpha; CBUFFER_END struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; }; struct Varyings { float4 positionHCS : SV_POSITION; }; Varyings vert (Attributes input) { Varyings output; float t = 0.3333333; float widthScale = lerp(_InnerWidthScale, _OuterWidthScale, t); float3 posOS = input.positionOS.xyz + input.normalOS * (_OutlineWidth * widthScale); output.positionHCS = TransformObjectToHClip(posOS); return output; } half4 frag (Varyings input) : SV_Target { float t = 0.3333333; float alpha = lerp(_InnerAlpha, _OuterAlpha, t); return half4(_OutlineColor.rgb * _Emission, _OutlineColor.a * alpha); } ENDHLSL } Pass { Name "OutlineLayer2" Tags { "LightMode"="UniversalForward" } Cull Front ZWrite Off ZTest LEqual Blend SrcAlpha One HLSLPROGRAM #pragma vertex vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" CBUFFER_START(UnityPerMaterial) float4 _OutlineColor; float _OutlineWidth; float _Emission; float _InnerWidthScale; float _OuterWidthScale; float _InnerAlpha; float _OuterAlpha; CBUFFER_END struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; }; struct Varyings { float4 positionHCS : SV_POSITION; }; Varyings vert (Attributes input) { Varyings output; float t = 0.6666667; float widthScale = lerp(_InnerWidthScale, _OuterWidthScale, t); float3 posOS = input.positionOS.xyz + input.normalOS * (_OutlineWidth * widthScale); output.positionHCS = TransformObjectToHClip(posOS); return output; } half4 frag (Varyings input) : SV_Target { float t = 0.6666667; float alpha = lerp(_InnerAlpha, _OuterAlpha, t); return half4(_OutlineColor.rgb * _Emission, _OutlineColor.a * alpha); } ENDHLSL } } }