消融效果

消融效果

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);
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容