Unity3D Ui利用shader添加效果
作者:htwzl 时间:2022-09-17 15:32:47
本文实例为大家分享了Unity3D Ui利用shader添加效果的具体代码,供大家参考,具体内容如下
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UI/Unlit/Flowlight"
{
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
_Color("Tint", Color) = (1, 1, 1, 1)
[MaterialToggle] _OffSet("OffSet", float) = 0
[MaterialToggle] PixelSnap("Pixel snap", float) = 0
/* Flowlight */
_FlowlightMaskTex("Mask Texture", 2D) = "white" {}
_FlowlightTex("Add Move Texture", 2D) = "white" {}
_FlowlightColor("Flowlight Color", Color) = (0, 0, 0, 1)
_Power("Power", float) = 1
_SpeedX("SpeedX", float) = 1
_SpeedY("SpeedY", float) = 0
/* --------- */
/* UI */
_StencilComp("Stencil Comparison", Float) = 8
_Stencil("Stencil ID", Float) = 0
_StencilOp("Stencil Operation", Float) = 0
_StencilWriteMask("Stencil Write Mask", Float) = 255
_StencilReadMask("Stencil Read Mask", Float) = 255
/* -- */
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
/* UI */
Stencil
{
Ref[_Stencil]
Comp[_StencilComp]
Pass[_StencilOp]
ReadMask[_StencilReadMask]
WriteMask[_StencilWriteMask]
}
/* -- */
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ PIXELSNAP_ON
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
/* Flowlight */
half2 texflowlight : TEXCOORD1;
/* --------- */
};
fixed4 _Color;
/* Flowlight */
fixed4 _FlowlightColor;
float _Power;
sampler2D _FlowlightTex;
fixed4 _FlowlightTex_ST;
sampler2D _FlowlightMaskTex;
fixed4 _FlowlightMaskTex_ST;
fixed _SpeedX;
fixed _SpeedY;
fixed x = 0;
float _OffSet;
/* --------- */
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
/* Flowlight */
OUT.texflowlight = TRANSFORM_TEX(IN.texcoord, _FlowlightTex);
OUT.texflowlight.x += _Time * _SpeedX;
OUT.texflowlight.y += _Time * _SpeedY;
OUT.color = IN.color * _Color;
#ifdef PIXELSNAP_ON
OUT.vertex = UnityPixelSnap(OUT.vertex);
#endif
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = tex2D(_MainTex, IN.texcoord)*IN.color;
fixed4 cmask = tex2D(_FlowlightMaskTex, IN.texcoord);
if (cmask.a != 0)
{
/* Flowlight */
fixed4 cadd = tex2D(_FlowlightTex, IN.texflowlight) * _Power;
cadd.rgb *= c.rgb;
c.rgb += cadd.rgb;
}
c.rgb *= c.a;
/* --------- */
return c;
}
ENDCG
}
}
}
来源:https://blog.csdn.net/htwzl/article/details/78184248
标签:Unity3D,shader
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
浅谈一下Java的双亲委派模式
2021-11-12 02:48:17
![](https://img.aspxhome.com/file/2023/6/88166_0s.jpg)
详解Java中restTemplate的使用
2023-06-19 23:20:29
Java ShutdownHook原理详解
2023-11-10 21:30:36
![](https://img.aspxhome.com/file/2023/7/58457_0s.png)
Kotlin语言编程Regex正则表达式实例详解
2023-06-22 02:06:29
Java信号量Semaphore原理及代码实例
2021-10-02 21:55:08
java中LinkedList使用迭代器优化移除批量元素原理
2021-12-05 11:26:07
![](https://img.aspxhome.com/file/2023/0/66180_0s.png)
IO中flush()函数的使用代码示例
2023-11-27 03:49:00
![](https://img.aspxhome.com/file/2023/4/60044_0s.gif)
详解Java线程池如何统计线程空闲时间
2022-11-09 07:41:10
@RequestBody的使用案例代码
2021-07-11 16:46:50
Java实现身份证号码验证源码示例分享
2022-12-24 03:58:50
详解SpringBoot+SpringSecurity+jwt整合及初体验
2023-11-28 23:54:48
![](https://img.aspxhome.com/file/2023/3/60373_0s.png)
Java多线程死锁与资源限制操作
2023-08-31 05:54:30
SpringBoot实战之高效使用枚举参数(原理篇)案例详解
2022-02-10 23:54:23
![](https://img.aspxhome.com/file/2023/5/77055_0s.jpg)
SpringBoot整合Mybatis自定义拦截器不起作用的处理方案
2023-03-19 04:35:14
![](https://img.aspxhome.com/file/2023/7/77937_0s.png)
C#格式化json字符串的方法分析
2023-12-23 00:20:36
Hibernate一级缓存和二级缓存详解
2023-11-16 11:58:11
分布式调度XXL-Job整合Springboot2.X实战操作过程(推荐)
2023-11-23 09:43:38
![](https://img.aspxhome.com/file/2023/9/59869_0s.jpg)
Java实现人机猜拳小游戏
2023-10-07 16:11:37
![](https://img.aspxhome.com/file/2023/1/58681_0s.jpg)
深入分析Java异常
2022-10-29 16:06:40
C#结合AForge实现摄像头录像
2021-06-28 03:53:51
![](https://img.aspxhome.com/file/2023/5/76425_0s.png)