• [Shader]一个类似暗黑3血条的效果


    <1>效果图

    <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

    [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;

    fixed4 frag(v2f IN) : SV_Target
    {
    half2 uv = IN.texcoord;
    half4 col = IN.color;
    _Conc = (_Conc*-1) + 6;
    _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);

    //uv += no1.xy;

    col.a -= no1.x*no2.x*no3.x*_Conc;
    col.a *= _Trans;

    //Fill 波纹
    half q = sin((_Time.x + uv.x)%PI);//1 0 1
    half t = _Time.x%PI;
    //half val = sin(_Time.x % PI);//0-1-0

    half val = sin((_Time.x+t- uv.x)*10 % PI);//0 -1 -0

    //X高度 0-1-0
    //0 0.05 0
    val = val*0.05;

    col.a = 1-(uv.y+val) > _Fill ? 0: col.a;

    //圆周
    half dis = length(uv - float2(0.5, 0.5));
    col.a = dis > 0.45 ? 1 : col.a;

    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
    }
    }
    }

  • 相关阅读:
    jstl嵌套以及输出json的逗号
    关闭win10 更新以后自动重启
    maven 配置错误。
    SQL SERVER 订阅发布在restore DB以后的问题
    Unable to convert MySQL date/time value to System.DateTime
    sql server恢复卡在restoring的解决方法
    打开Excel时总是运行Windows Installer(Visual studio)解决方法
    单元测试用excel connstr
    node.js调试
    javascript数组对象实例方法
  • 原文地址:https://www.cnblogs.com/cocotang/p/7406691.html
Copyright © 2020-2023  润新知