[Shader]暗黑3血条效果2

Posted tianjiuwan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Shader]暗黑3血条效果2相关的知识,希望对你有一定的参考价值。

<1>效果图1直线瓶颈  效果图2波浪瓶颈

               

<2>添加破浪     

half val =uv.y+ sin((uv.x * 4 + _Time.y * 4))*0.8; 
val *= 0.1;

col.a = uv.y+val > _Fill ? 0 : col.a;

<2>源码

Shader "UI/UI2"
{
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
_Noise("_Noise 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
_Speed("速度",Range(0,1)) = 1
_Fill("高度",Range(0,1)) = 1
_Conc("浓度",Range(1,5)) = 1
_Trans("透明度",Range(0,1)) = 1
_BlendX("混合贴图X",2D) = "white" {}
_BlendY("混合贴图Y",2D) = "white" {}

[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;
float _Speed;
float _Fill;
float _Conc;
float _Trans;

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;
sampler2D _Noise;
sampler2D _GrabTexture;
sampler2D _BlendX;
sampler2D _BlendY;

fixed4 frag(v2f IN) : SV_Target
{
half2 uv = IN.texcoord;
half4 col = IN.color;
_Speed = _Speed*0.1;

//采样噪声图
half4 no1 = tex2D(_Noise, uv + _Time.xz*_Speed);
half4 no2 = tex2D(_Noise, uv - _Time.zx*_Speed);
half4 no3 = tex2D(_Noise, uv - _Time.yz*_Speed);

if (_Fill - uv.y < 0.02) {
_Color *= 20;
//_Color. = 0;
_Color.b = 0;
_Color.a = sin(_Time.y%PI);
}

col.a = uv.y > _Fill ? 0 : col.a;
col.a *= _Trans;

half4 color = (tex2D(_MainTex, uv)*tex2D(_BlendX, float2(no1.x,no2.x))*tex2D(_BlendY, uv*float2(no2.x,no3.x))*_Color + _TextureSampleAdd);
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
color.a *= col.a;
#ifdef UNITY_UI_ALPHACLIP
clip(color.a - 0.001);
#endif

return color;
}
ENDCG
}
}
}

        

以上是关于[Shader]暗黑3血条效果2的主要内容,如果未能解决你的问题,请参考以下文章

Unity3D 多层血条特效

Unity3D 多层血条特效

unity3d中怎样制作血条跟随角色运动

Unity3D 血条的渐变效果

Unity3D 血条的渐变效果

学unityshader之前学unity吗