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

  • 相关阅读:
    mysql常用基本命令
    mysql8.0.13下载与安装图文教程
    k8s ingress 增加跨域配置
    Jenkins 备份恢复插件 thinBackup 使用
    k8s HA master 节点宕机修复
    nginx 跨域问题解决
    mongodb 3.4.24 主从复制
    k8s 线上安装 jenkins并结合 jenkinsfile 实现 helm 自动化部署
    k8s helm 运用与自建helm仓库chartmuseum
    centos6 源码安装 unzip
  • 原文地址:https://www.cnblogs.com/cocotang/p/7339050.html
Copyright © 2011-2022 走看看