博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Shader]一个shader效果啦(那个lost soul aside里面看到的)
阅读量:4318 次
发布时间:2019-06-06

本文共 3246 字,大约阅读时间需要 10 分钟。

<1>效果图和原图

思路:初始扩散以()0.5,0)为圆心扩散,计算UV坐标到圆心距离,初始扩散完毕,从下到上改变alpha就好啦

代码:

float2 uv = IN.texcoord.xy;

fixed4 col = IN.color;
float timer = _Time.y;
if (timer > 2.5) {
timer = timer - 2.5;
float h = timer/2 % 1;
if (h - uv.y > 0.2 || h - uv.y < 0)//循环流动
col.a = 0.4;
else {
float val = (1 - (h - uv.y));//0.8~1 
col.a = val*val*val;//扩大0.8~1
}
}
else {
float dis = timer/2 % 1.5;//0-1 UV.Y//初始扩散
float len = length(uv - float2(0.5, 0));
dis = dis - len;
if (dis< 0)
col.a = 0;
if (dis>0)
col.a = 1 - dis>0.4?1-dis:0.4;
}

clip(col.a - 0.01);

完整代码:

// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

Shader "Tang/UIFlashVertical"

{
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
_Color("Tint", Color) = (1,1,1,1)

_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

_ColorMask("Color Mask", Float) = 15

//my member

[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0

}

SubShader

{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}

Stencil

{
Ref[_Stencil]
Comp[_StencilComp]
Pass[_StencilOp]
ReadMask[_StencilReadMask]
WriteMask[_StencilWriteMask]
}

Cull Off

Lighting Off
ZWrite Off
ZTest[unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask[_ColorMask]

Pass

{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0

#include "UnityCG.cginc"

#include "UnityUI.cginc"

#pragma multi_compile __ UNITY_UI_ALPHACLIP

#define PI 3.1415926

struct appdata_t

{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct v2f

{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};

fixed4 _Color;

fixed4 _TextureSampleAdd;
float4 _ClipRect;

v2f vert(appdata_t IN)

{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.worldPosition = IN.vertex;
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);

OUT.texcoord = IN.texcoord;

OUT.color = IN.color * _Color;

return OUT;
}

sampler2D _MainTex;

fixed4 frag(v2f IN) : SV_Target

{
float2 uv = IN.texcoord.xy;
fixed4 col = IN.color;
//从下到上 以0.5,0为圆心扩散
float timer = _Time.y;
if (timer > 2.5) {
timer = timer - 2.5;
float h = timer/2 % 1;
if (h - uv.y > 0.2 || h - uv.y < 0)
col.a = 0.4;
else {
float val = (1 - (h - uv.y));
col.a = val*val*val;
}
}
else {
float dis = timer/2 % 1.5;//0-1 UV.Y
float len = length(uv - float2(0.5, 0));
dis = dis - len;
if (dis< 0)
col.a = 0;
if (dis>0)
col.a = 1 - dis>0.4?1-dis:0.4;
}

clip(col.a - 0.01);

half4 color = (tex2D(_MainTex, uv) + _TextureSampleAdd) * col;

color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);

#ifdef UNITY_UI_ALPHACLIP

clip(color.a - 0.001);
#endif

return color;

}
ENDCG
}
}
}

 

 

-------------------------------------分割线---------------------------------------

有些效果写到github里面了,我的Github:https://github.com/tianjiuwan

转载于:https://www.cnblogs.com/cocotang/p/7339050.html

你可能感兴趣的文章
IOS 发布 升级新版本
查看>>
上传绕过补充
查看>>
sql-leetcode Consecutive Numbers
查看>>
C# winform DataGridView操作 (转)
查看>>
一致性Hash算法及使用场景
查看>>
JS - Lexical Structure
查看>>
【2】oracle创建表空间
查看>>
剑指offer-二叉树中和为某一值的路径
查看>>
Java反射机制
查看>>
Python 正则表达式
查看>>
C++ AppendMenu
查看>>
在所选中的物体中取消选中一些物体.txt
查看>>
grid - 网格项目跨行或跨列
查看>>
Shell 基本运算符
查看>>
2019年2月
查看>>
Google Noto Sans CJK 字体
查看>>
ES集群性能调优链接汇总
查看>>
STL库的应用
查看>>
spark算子
查看>>
(转)Linux服务器SNMP常用OID
查看>>