GitHub项目地址
消融的原理:噪声纹理+clip透明度测试
(1)噪声纹理实现随机性
(2)clip函数实现透明度测试
1、基础实现
fixed4 frag (v2f i) : SV_Target
{
fixed cutout = tex2D(_NoiseTex, i.uvNoise).r;
clip(cutout - _Threshold);
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
2、边缘纯颜色
fixed4 frag (v2f i) : SV_Target
{
fixed cutout = tex2D(_NoiseTex, i.uvNoise).r;
clip(cutout - _Threshold);
//边缘颜色
if(cutout - _Threshold < _EdgeLength)
return _EdgeColor;
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
3、边缘两种颜色混合
fixed4 frag (v2f i) : SV_Target
{
fixed cutout = tex2D(_NoiseTex, i.uvNoise).r;
clip(cutout - _Threshold);
//边缘颜色
if(cutout - _Threshold < _EdgeLength)
{
fixed percent = (cutout - _Threshold) / _EdgeLength;
return lerp(_EdgeStartColor, _EdgeEndColor, percent);
}
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
4、边缘颜色混合物体颜色
fixed4 frag (v2f i) : SV_Target
{
fixed cutout = tex2D(_NoiseTex, i.uvNoise).r;
clip(cutout - _Threshold);
//边缘颜色
fixed percent = saturate((cutout - _Threshold) / _EdgeLength);
fixed4 edgeColor = lerp(_EdgeStartColor, _EdgeEndColor, percent);
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 result = lerp(edgeColor, col, percent);
return fixed4(result.rgb, 1);
}
5、边缘使用渐变纹理
fixed4 frag (v2f i) : SV_Target
{
fixed cutout = tex2D(_NoiseTex, i.uvNoise).r;
clip(cutout - _Threshold);
//边缘颜色
fixed percent = saturate((cutout - _Threshold) / _EdgeLength);
fixed4 edgeColor = tex2D(_RampTex, float2(percent, percent));
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 result = lerp(edgeColor, col, percent);
return fixed4(result.rgb, 1);
}
网友评论