Shader "Unlit/PureExtrude"
{
Properties
{
_OutlineColor("Outline Color",Color) = (1,0.5,0,0.5)
_Outline("Outline",Range(0,1)) = 0.1
}
SubShader
{
Tags { "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline"}
Pass
{
Cull Off
ZTest LEqual
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Atributes
{
float4 posOS : POSITION;
float3 norOS : NORMAL;
};
struct Varyings
{
float4 posCS : SV_POSITION;
};
CBUFFER_START(UnityPerMaterial)
real4 _OutlineColor;
real _Outline;
CBUFFER_END
Varyings vert(Atributes v)
{
Varyings o = (Varyings)0;
o.posCS = TransformObjectToHClip(v.posOS.xyz);
float3 vNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, v.norOS));
float2 projPos = normalize(mul((float2x2)UNITY_MATRIX_P,vNormal.xy));
o.posCS.xy += projPos * _Outline * 0.1;
return o;
}
real4 frag(Varyings i) : SV_Target
{
return _OutlineColor;
}
ENDHLSL
}
}
}
这个Shader本来是准备做Outline用的,但是在URP使用多个Pass实在弄不好,所以就通过Render Feature的方式先渲染蒙版Stencil,再通过Stencil来扣掉挤出像素的内部,这样就形成了Outline效果。后续我们会使用这个Shader产生Outline的具体做法。