加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

U3D log Flash shader 效果(标题流光效果)

发布时间:2020-12-15 17:28:42 所属栏目:百科 来源:网络整理
导读:整理下用到的shader效果,其中用到最多的,或则很大几率在游戏中会用到的,可能是标题的流光效果, 如果用帧动画实现,不仅资源耗费明显,最终效果也没shader来得逼真,废话不多说,直接上代码了(其实也是根据网上shader小改了下得到的): Shader "Env/Log

整理下用到的shader效果,其中用到最多的,或则很大几率在游戏中会用到的,可能是标题的流光效果,

如果用帧动画实现,不仅资源耗费明显,最终效果也没shader来得逼真,废话不多说,直接上代码了(其实也是根据网上shader小改了下得到的):


Shader "Env/LogoFlash"? { ? ? ? Properties { ? ? ? ? ? //_MainTex ("Base (RGB)",2D) = "white" {} ? ? ? ? ? _MainTex ("Base (RGB),Alpha (A)",2D) = "white" {} ? ? ? ? _FlashColor ("Flash Color",Color) = (1,1,0) ? ? ? ? ? _Angle ("Flash Angle",Range(0,180)) = 45 ? ? ? ? ? _Width ("Flash Width",1)) = 0.2 ? ? ? ? ? _LoopTime ("Loop Time",Float) = 1 ? ? ? ? ? _Interval ("Time Interval",Float) = 3 ? // ? ? ? ?_BeginTime ("Begin Time",Float) = 2 ? ? ? } ? ? ? SubShader ? ? ? { ? ? ? ? ? Tags? ? ? ? ? {? ? ? ? ?"Queue"="Transparent"? ? ? ? ?"RenderType"="Transparent"? ? ? ? ? } ? // ? ? ?Blend SrcAlpha OneMinusSrcAlpha? // ? ? ?AlphaTest Greater 0.1 ? ? ? ? CGPROGRAM ? ? ? ? ? //#pragma surface surf Lambert alpha exclude_path:prepass noforwardadd ? ? ? ? ? #pragma surface surf Lambert alpha ? ? ? ? #pragma target 3.0 ? ? ? ? ? ? sampler2D _MainTex; ? ? ? ? ? float4 _FlashColor; ? ? ? ? ? float _Angle; ? ? ? ? ? float _Width; ? ? ? ? ? float _LoopTime; ? ? ? ? ? float _Interval; ? // ? ? ? ?float _BeginTime; ? ? ? ? ? ? ? ?? ? ? ? ? struct Input ?? ? ? { ? ? ? ? ? half2 uv_MainTex; ? ? ? }; ? ? ? ? ? ? ? ? ? ? ? ? float inFlash(half2 uv) ? ? ? ? ? { ? ?? ? ? ? ? ? ? float brightness = 0; ? ? ? ? ? ? ? ?? ? ? ? ? ? ? float angleInRad = 0.0174444 * _Angle; ? ? ? ? ? ? ? float tanInverseInRad = 1.0 / tan(angleInRad); ? ? ? ? ? ? ? ?? // ? ? ? ? ? ?float currentTime = _Time.y - _BeginTime; ? ? ? ? ?float currentTime = _Time.y; ? ? ? ? ?float totalTime = _Interval + _LoopTime; ? ? ? ? ? ? ? float currentTurnStartTime = (int)((currentTime / totalTime)) * totalTime; ? ? ? ? ? ? ? float currentTurnTimePassed = currentTime - currentTurnStartTime - _Interval; ? ? ? ? ? ? ? ?? ? ? ? ? ? ? bool onLeft = (tanInverseInRad > 0); ? ? ? ? ?float xBottomFarLeft = onLeft? 0.0 : tanInverseInRad; ? ? ? ? ?float xBottomFarRight = onLeft? (1.0 + tanInverseInRad) : 1.0; ? ? ? ? ? ? ? ?? ? ? ? ? float percent = currentTurnTimePassed / _LoopTime; ? ? ? ? ? ? ? float xBottomRightBound = xBottomFarLeft + percent * (xBottomFarRight - xBottomFarLeft); ? ? ? ? ? ? ? float xBottomLeftBound = xBottomRightBound - _Width; ? ? ? ? ? ? ? ?? ? ? ? ? ? ? float xProj = uv.x + uv.y * tanInverseInRad; ? ? ? ? ? ? ? ?? ? ? ? ? ? ? if(xProj > xBottomLeftBound && xProj < xBottomRightBound) ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? brightness = 1.0 - abs(2.0 * xProj - (xBottomLeftBound + xBottomRightBound)) / _Width; ? ? ? ? ? ? ? } ? ?? ? ? ? ? ? ? return brightness; ? ? ? ? ? } ? ? ? ? ? ?? ? ? ? ? void surf (Input IN,inout SurfaceOutput o) ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? float4 texCol = tex2D(_MainTex,IN.uv_MainTex); ? ? ? ? ? ? ? float brightness = inFlash(IN.uv_MainTex); ? ? ? ? ? ?? ? ? ? ? ? ? o.Albedo = texCol.rgb + _FlashColor.rgb * brightness; ? ? ? ? ? ? ? //o.Alpha = ?texCol.a; ?? ? ? ? ? ? ? o.Alpha = texCol.a * ?brightness; ? ? ? ? } ? ? ? ? ? ?? ? ? ? ? ENDCG ? ? ?? ? ? } ? ? ? ?? ? ? FallBack "Unlit/Transparent GrayscaleEffect" ? } ?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读