我正在使用着色器来统一色度键效果。虽然可以完成工作,但是我需要在人才周围设置柔和的边缘。如果我能如下图所示模糊Alpha通道,我相信边缘会很柔和
SubShader{
Tags {"Queue" = "Transparent""IgnoreProjector" = "True""RenderType" = "Transparent"}
Lighting Off
ZWrite Off
AlphaTest Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
sampler2D _MainTex;
float _Sensitivity;
float _Smooth;
float _Top;
float _Bottom;
float _Left;
float _Right;
float _Brightness;
float _Red;
float _Green;
float _Blue;
float edge_color;
uniform float4 _MaskCol;
#include "UnityCG.cginc"
float4 frag(v2f_img i) : COLOR{
float3 input_color = tex2D(_MainTex,i.uv).rgb;
float d = abs(length(abs((_MaskCol.rgb) - (input_color.rgb))));
float edge0 = _Sensitivity * _Smooth;
float alpha = smoothstep(edge0, _Sensitivity,d);
if (edge_color == 1) {
if (input_color.g > input_color.r && input_color.g > input_color.b) {
input_color.g = input_color.b; input_color.r = input_color.b;
}
}
if (i.uv.x<_Left || i.uv.x>(1 - _Right))
{
alpha = 0;
};
if (i.uv.y<_Bottom || i.uv.y>(1 - _Top))
{
alpha = 0;
};
return float4(input_color*_Brightness,alpha);
}
ENDCG
}
}
FallBack"Unlit/Texture"
}
有什么想法可以实现这一目标或有其他不同的建议?