如图 http://clynamen.github.io/blog/2014/06/24/outline-in-unity-with-mesh-transparency/
Shader "MyURP/Grid_EdgeHighLight"
{
Properties
{
_BaseColor("Base Color", Color) = (1, 1, 1, 1)
_BaseMap("Base Map", 2D) = "white" {}
_Thickness("_Thickness", range(0, 10)) = 1
_AlphaInner("_AlphaInner", range(0, 1)) = 0.1
}
SubShader
{
Tags
{
"RenderPipeline"="UniversalRenderPipeline"
"RenderType"="Transparent"
"IgnoreProjector"="True"
"Queue"="Transparent"
}
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite On
Tags
{
"LightMode" = "SRPDefaultUnlit"
}
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
float2 uv : TEXCOORD0;
};
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
half4 _BaseColor;
float4 _BaseMap_ST;
float _Thickness;
float _AlphaInner;
CBUFFER_END
Varyings vert(Attributes IN)
{
Varyings o;
o.uv = IN.uv;
o.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
return o;
}
half4 frag(Varyings IN) : SV_Target
{
half4 col = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv) * _BaseColor;
col.a = _AlphaInner;
return col;
}
ENDHLSL
}
Pass
{
Name "Outline"
Tags
{
"LightMode" = "UniversalForward"
}
Cull Back
ZWrite On
ZTest Less
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Offset 15,15
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
float2 uv : TEXCOORD0;
};
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
half4 _BaseColor;
float4 _BaseMap_ST;
float _Thickness;
CBUFFER_END
Varyings vert(Attributes IN)
{
Varyings o;
o.uv = IN.uv;
float3 dir = IN.positionOS.xyz - float3(0, 0, 0);
dir = TransformObjectToWorldDir(dir);
float3 worldPos = TransformObjectToWorld(IN.positionOS.xyz);
worldPos += dir * 2 * _Thickness;
o.positionHCS = TransformWorldToHClip(worldPos);
return o;
}
half4 frag(Varyings IN) : SV_Target
{
half4 col = _BaseColor;
return col;
}
ENDHLSL
}
}
}
|