U3D log Flash shader 效果(标题流光效果)
2015-01-07 15:54
225 查看
整理下用到的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,1,0)
_Angle ("Flash Angle", Range(0, 180)) = 45
_Width ("Flash Width", Range(0, 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"
}
如果用帧动画实现,不仅资源耗费明显,最终效果也没shader来得逼真,废话不多说,直接上代码了(其实也是根据网上shader小改了下得到的):
Shader "Env/LogoFlash"
{
Properties {
//_MainTex ("Base (RGB)", 2D) = "white" {}
_MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
_FlashColor ("Flash Color", Color) = (1,1,1,0)
_Angle ("Flash Angle", Range(0, 180)) = 45
_Width ("Flash Width", Range(0, 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"
}
相关文章推荐
- 可拖动FLASH+XML图片展示效果【点击放大带标题内容】
- Unity3D Shader 模型流光效果
- [UnityShader3]圆角与流光效果
- jqeury仿flash图片联动标题效果
- 转载{shader流光效果}
- Unity3D 通过 shader 实现流光效果
- Unity Shader-非主流纹理采样研究(流光,溶解,隐身效果)
- 今天写shader流光效果,shader代码少了个括号,unity shader compiler卡死且不提示原因
- shader 流光效果
- 滑动效果——ListView 滑动中标题固定&标题缩放效果
- unity shader 实现常见的混合效果
- 怎么实现我要的flash效果呀
- H5实现仿flash效果的实现代码
- 【Shader】人物在墙一侧透视效果
- html控制左边图右边标题效果
- Shader第五讲:LOGO闪光效果
- jquery上下翻滚效果导航菜单(仿flash)
- JavaScript 类似flash效果的立体图片浏览器
- JQuery实现的简洁Flash幻灯渐变效果
- flash特效原理:图片滑动放大效果(3)