标签:
总算找到了一个实用的效果,就拿出来给大家分享一下。
1 Shader "Custom/LOGOblink" { 2 Properties { 3 _MainTex ("Base (RGB)", 2D) = "white" {} 4 5 _BlinkColor ( "Blink Color", color ) = (1,1,1,1) 6 _BlinkWidth ( "Blink Width", range(0, 1) ) = 0.2 7 _LoopTime ( "Looping Time", range(0,10)) = 1 8 _Interval ( "Time Interval", range(0,10)) = 2 9 } 10 SubShader { 11 Tags { "RenderType"="Opaque" } 12 LOD 200 13 14 CGPROGRAM 15 #pragma surface surf Lambert 16 17 sampler2D _MainTex; 18 float4 _BlinkColor; 19 float _BlinkWidth; 20 float _LoopTime; 21 float _Interval; 22 23 24 struct Input { 25 float2 uv_MainTex; 26 }; 27 28 float Blink( float2 uv ) 29 { 30 31 float curTime = _Time.y; // 当前时间 32 float totalTime = _LoopTime + _Interval; 33 float curInitTime = (int)(_Time.y / totalTime) * totalTime; // 当前起始时间 34 35 float passedTime = _Time.y - curInitTime - _Interval; 36 37 if(passedTime <= 0.0) 38 return 0.0; 39 else 40 { 41 float passedTimePercent = (passedTime) / _LoopTime; 42 43 44 float bottomPoint1 = passedTimePercent*(_BlinkWidth + 1); // 底点1 45 float bottomPoint2 = bottomPoint1 - _BlinkWidth; // 底点2 46 // 默认是45度角,所以不需要太多计算 47 48 float temp1 = bottomPoint1 - uv.y; 49 float temp2 = temp1 - (_BlinkWidth*0.5); 50 51 52 if( uv.x > temp1 || uv.x < temp1-_BlinkWidth) 53 return 0.0; 54 else 55 { 56 return 1.0- abs( (temp1 - uv.x - temp2) / temp2 ); 57 } 58 } 59 } 60 61 62 void surf (Input IN, inout SurfaceOutput o) { 63 half4 c = tex2D (_MainTex, IN.uv_MainTex); 64 float brightness = Blink(IN.uv_MainTex); 65 66 o.Albedo = c.rgb + ( brightness * _BlinkColor.rgb ); 67 o.Alpha = c.a; 68 } 69 ENDCG 70 71 } 72 FallBack "Diffuse" 73 }
并没有太多难度,有一个创意的部分,就是用除法归整实现计数。(这是被逼出来的招么?>_<)
注意事项:
1.UV坐标原点是左下角。
2.区别于C语言,一个分支部分有return,就必须显式地写出来else部分。
****************
标签:
原文地址:http://www.cnblogs.com/SecretMan001/p/4510436.html