You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.5 KiB
Plaintext
91 lines
2.5 KiB
Plaintext
Shader "Custom/TransparentOutline"
|
|
{
|
|
Properties
|
|
{
|
|
_MainColor ("Main Color", Color) = (1,1,1,0.5)
|
|
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
|
|
_OutlineWidth ("Outline Width", Range(0.001, 0.1)) = 0.02
|
|
}
|
|
SubShader
|
|
{
|
|
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
|
|
LOD 100
|
|
|
|
// First Pass: Render the Outline Behind the Mesh
|
|
Pass {
|
|
Name "Outline"
|
|
Cull Front
|
|
ZWrite Off
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
|
|
struct appdata_t {
|
|
float4 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
};
|
|
|
|
struct v2f {
|
|
float4 positionCS : SV_POSITION;
|
|
};
|
|
|
|
float _OutlineWidth;
|
|
float4 _OutlineColor;
|
|
|
|
v2f vert(appdata_t v) {
|
|
v2f o;
|
|
float3 normalWS = TransformObjectToWorldNormal(v.normalOS);
|
|
float3 positionWS = TransformObjectToWorld(v.positionOS.xyz);
|
|
positionWS += normalWS * _OutlineWidth;
|
|
o.positionCS = TransformWorldToHClip(positionWS);
|
|
return o;
|
|
}
|
|
|
|
half4 frag(v2f i) : SV_Target {
|
|
return _OutlineColor;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
// Second Pass: Render the Transparent Mesh on Top
|
|
Pass {
|
|
Name "Main"
|
|
Cull Back
|
|
ZWrite Off
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
|
|
struct appdata_t {
|
|
float4 positionOS : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct v2f {
|
|
float4 positionCS : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
float4 _MainColor;
|
|
|
|
v2f vert(appdata_t v) {
|
|
v2f o;
|
|
o.positionCS = TransformObjectToHClip(v.positionOS);
|
|
o.uv = v.uv;
|
|
return o;
|
|
}
|
|
|
|
half4 frag(v2f i) : SV_Target {
|
|
return _MainColor;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
}
|