Unity shader实现消融效果
作者:贪玩的孩纸时代 时间:2023-03-06 01:06:44
本文实例为大家分享了Unity shader实现消融效果的具体代码,供大家参考,具体内容如下
效果图:
shader代码:
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Custom/EdgeColo" {
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_NoiseTex("Noise", 2D) = "white" {}
_Threshold("Threshold", Range(0.0, 1.0)) = 0.5
_EdgeLength("Edge Length", Range(0.0, 0.2)) = 0.1
_EdgeColor("Edge Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "Queue"="Geometry" "RenderType"="Opaque" }
Pass
{
Cull Off //要渲染背面保证效果正确
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uvMainTex : TEXCOORD0;
float2 uvNoiseTex : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _NoiseTex;
float4 _NoiseTex_ST;
float _Threshold;
float _EdgeLength;
fixed4 _EdgeColor;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uvMainTex = TRANSFORM_TEX(v.uv, _MainTex);
o.uvNoiseTex = TRANSFORM_TEX(v.uv, _NoiseTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
//镂空
fixed cutout = tex2D(_NoiseTex, i.uvNoiseTex).r;
clip(cutout - _Threshold);
//边缘颜色
if(cutout - _Threshold < _EdgeLength)
return _EdgeColor;
fixed4 col = tex2D(_MainTex, i.uvMainTex);
return col;
}
ENDCG
}
}
}
使用方法:建一个材质球,选择此shader,然后选择一个噪声图(即:Noise),最后修改Threshold和EdgeLength参数即可看到效果。
来源:https://blog.csdn.net/yiwei151/article/details/78621068
标签:Unity,shader,消融
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
浅谈springboot的三种启动方式
2022-07-31 10:57:47
![](https://img.aspxhome.com/file/2023/5/67965_0s.png)
java利用递归算法实现对文件夹的删除功能
2023-07-26 06:37:02
C#启动进程的几种常用方法
2023-06-18 04:13:48
Android studio实现PopupWindow弹出框效果
2021-12-19 11:12:50
![](https://img.aspxhome.com/file/2023/1/126721_0s.jpg)
springboot整合@Retryable实现重试功能的示例代码
2023-11-27 11:08:20
.NET实现:将EXE设置开机自动启动
2022-02-25 05:49:25
![](https://img.aspxhome.com/file/2023/8/108618_0s.png)
C#后台接受前台JSON字符串装换成字典集合处理
2023-07-03 02:38:55
java编程实现根据EXCEL列名求其索引的方法
2022-04-24 03:08:03
第1个Android应用程序 Android制作简单单页导航
2022-09-27 22:23:26
![](https://img.aspxhome.com/file/2023/0/122050_0s.png)
Activiti流程图查看实例
2022-09-10 17:51:44
使用注解解决ShardingJdbc不支持复杂SQL方法
2022-08-03 02:15:12
![](https://img.aspxhome.com/file/2023/5/63795_0s.png)
Android完整Socket解决方案
2023-12-22 14:42:40
理解java设计模式之建造者模式
2023-03-13 14:48:55
C#在图片增加文字的实现代码
2023-03-30 03:26:24
Spring Boot之AOP配自定义注解的最佳实践过程
2023-01-27 17:41:02
![](https://img.aspxhome.com/file/2023/4/77334_0s.gif)
Android实现秒表功能
2023-08-21 02:15:41
![](https://img.aspxhome.com/file/2023/5/95985_0s.jpg)
Ajax实现省市区三级联动
2023-01-14 05:09:58
![](https://img.aspxhome.com/file/2023/3/71663_0s.png)
详解 Java中日期数据类型的处理之格式转换的实例
2021-12-29 05:17:49
winform实现五子棋游戏
2023-05-31 19:14:24
接口签名怎么用Java实现
2023-02-18 03:22:10
![](https://img.aspxhome.com/file/2023/3/61853_0s.png)