zoukankan      html  css  js  c++  java
  • [Shader]一个shader效果啦(那个lost soul aside里面看到的)

    <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

  • 相关阅读:
    EasyUI--Alert()
    asp.net 页面之间传值的几种方式
    c# 的类成员
    c# protected public private internal
    C#中的多态性
    c# 静态成员和实例成员的区别
    js确认框confirm()用法实例详解
    JS中的switch case
    分分钟用上C#中的委托和事件
    Asp.net MVC中关于@Html标签Label、Editor使用
  • 原文地址:https://www.cnblogs.com/cocotang/p/7339050.html
Copyright © 2011-2022 走看看