广告合作
  • 今日头条

    今日头条

  • 百度一下

    百度一下,你就知道

  • 新浪网

    新浪网 - 提供新闻线索,重大新闻爆料

  • 搜狐

    搜狐

  • 豆瓣

    豆瓣

  • 百度贴吧

    百度贴吧——全球领先的中文社区

  • 首页 尚未审核订阅工具 订阅

    Unity Shader教程之 UGUI扫光效果的实现

    来源:网络收集  点击:  时间:2024-03-13
    【导读】:
    Unity Shader教程之 UGUI扫光效果的实现。本节介绍,在Unity开发中,UGUI实现扫光效果,具体如下工具/原料moreUnity方法/步骤1/7分步阅读

    打开Unity,新建一个空工程,导入中一张图片,具体如下图

    2/7

    在场景中,新建一个Image,适当合理布局,具体如下

    3/7

    在工程中新建Shader,命名为 FlowLightShader,双击打开进行编辑,具体如下图

    4/7

    FlowLightShader 脚本的具体内容如下:

    ShaderCustom/FlowLightShader{

    Properties{

    _MainTex(Base(RGB),2D)=white{}

    _FlashColor(FlashColor,Color)=(1,1,1,1)

    _Angle(FlashAngle,Range(0,180))=45

    _Width(FlashWidth,Range(0,1))=0.2

    _LoopTime(LoopTime,Float)=0.5

    _Interval(TimeInterval,Float)=1.5

    }

    SubShader

    {

    Tags{Queue=TransparentRenderType=Transparent}

    LOD200

    BlendSrcAlphaOneMinusSrcAlpha

    CGPROGRAM

    #pragmasurfacesurfLambertalphaexclude_path:prepassnoforwardadd

    sampler2D_MainTex;

    float4_FlashColor;

    float_Angle;

    float_Width;

    float_LoopTime;

    float_Interval;

    structInput

    {

    half2uv_MainTex;

    };

    floatinFlash(half2uv)

    {

    floatbrightness=0;

    floatangleInRad=0.0174444*_Angle;

    floattanInverseInRad=1.0/tan(angleInRad);

    floatcurrentTime=_Time.y;

    floattotalTime=_Interval+_LoopTime;

    floatcurrentTurnStartTime=(int)((currentTime/totalTime))*totalTime;

    floatcurrentTurnTimePassed=currentTime-currentTurnStartTime-_Interval;

    boolonLeft=(tanInverseInRad0);

    floatxBottomFarLeft=onLeft?0.0:tanInverseInRad;

    floatxBottomFarRight=onLeft?(1.0+tanInverseInRad):1.0;

    floatpercent=currentTurnTimePassed/_LoopTime;

    floatxBottomRightBound=xBottomFarLeft+percent*(xBottomFarRight-xBottomFarLeft);

    floatxBottomLeftBound=xBottomRightBound-_Width;

    floatxProj=uv.x+uv.y*tanInverseInRad;

    if(xProjxBottomLeftBoundxProjxBottomRightBound)

    {

    brightness=1.0-abs(2.0*xProj-(xBottomLeftBound+xBottomRightBound))/_Width;

    }

    returnbrightness;

    }

    voidsurf(InputIN,inoutSurfaceOutputo)

    {

    half4texCol=tex2D(_MainTex,IN.uv_MainTex);

    floatbrightness=inFlash(IN.uv_MainTex);

    o.Emission=texCol.rgb+_FlashColor.rgb*brightness;//改为输出Emission,不受光影响

    o.Alpha=texCol.a;

    }

    ENDCG

    }

    FallBackDiffuse

    }

    5/7

    脚本编译正确,回到Unity,在工程中,新建一个 Material,然后 Shader 通道设置为 新建的 Shader,简单的设置参数,具体如下图

    6/7

    把材质赋给Image,然后把贴图设置为 sprite,也赋给 Image,具体如下图

    7/7

    运行场景,

    注意事项

    您的支持,是我们不断坚持知识分享的动力,若帮到您,还请帮忙投票有得;若有疑问,请留言

    UNITYSHADER扫光效果UGUI扫光效果
    本文关键词:

    版权声明:

    1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。

    2、本站仅提供信息发布平台,不承担相关法律责任。

    3、若侵犯您的版权或隐私,请联系本站管理员删除。

    4、文章链接:http://www.1haoku.cn/art_336668.html

    ©2019-2020 http://www.1haoku.cn/ 国ICP备20009186号07-13 01:00:37  耗时:0.025