您的位置:首页 > 其它

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"

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: