消融效果

消融效果

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);
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容