
消融效果
GitHub項目地址
消融的原理:噪聲紋理+clip透明度測試
(1)噪聲紋理實(shí)現(xiàn)隨機(jī)性
(2)clip函數(shù)實(shí)現(xiàn)透明度測試
1、基礎(chǔ)實(shí)現(xiàn)
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);
}