Unity3d Tutorial Shader article: Fifth, the logo flash effect

Source: Internet
Author: User

reprinted from the Wind Yu Chong Unity3d Tutorial College



This effect will be used in many logos and advertising campaigns. Business development should be a flash of the map, UV-Mobile, and then with the original image of two images mixed, so that the operation will be much smaller, the need to store the variables are much smaller. This talk does not use a diagram and completely calculate the flash area, mainly to deepen the UV calculation to achieve the special effect of the implementation, as well as the method of calculating UV. Code comments with the diagram has been more detailed, and then do the line, casually find a translucent map to do maps.

 

Shader "Custom/logo" {Properties {_maintex ("Texture", 2D) = "white" {}} subshader {Alphate            St Greater. 2 Pass {cgprogram #pragma vertex vert #pragma fragment Frag            #include "unitycg.cginc" sampler2d _maintex;                       FLOAT4 _maintex_st;                struct V2F {float4 pos:sv_position;            FLOAT2 uv:texcoord0;                       };                   The vertex function is nothing special, as usual v2f vert (Appdata_base v) {v2f o;                O.pos = Mul (Unity_matrix_mvp,v.vertex);                O.UV = Transform_tex (V.texcoord,_maintex);            return o;            }//must be placed before using its frag function, otherwise it will not be recognized. Core: Compute function, angle, UV, x length of light band, interval, start time, offset, single cycle time float Inflash (float angle,float2 uv,float xlength,int Interval,int Beg InTime, float offx, float looptime) {//Luminance value                float brightness = 0;                               Tilt angle Float Angleinrad = 0.0174444 * ANGLE;                           Current time float currenttime = _time.y;                Gets the start time of this illumination int currenttimeint = _time.y/interval;                               Currenttimeint *=interval;                Gets the elapsed time of this illumination = current time-start time float currenttimepassed = currenttime-currenttimeint; if (currenttimepassed >begintime) {//bottom left and right boundary float XBOTTOMLEFTBO                    und                    float Xbottomrightbound;                    This point boundary float xpointleftbound;                                       float Xpointrightbound;                    float x0 = currenttimepassed-begintime;                               X0/= looptime;                                       Set right boundary xbottomrightbound = x0;Set left Border Xbottomleftbound = X0-xlength;                    The length of the projection to x = Y/tan (angle) float XPROJL;                    Xprojl= (UV.Y)/tan (Angleinrad);                    The left edge of this point = bottom left edge-the length of the projection to x xpointleftbound = XBOTTOMLEFTBOUND-XPROJL;                                       The right edge of this point = bottom right boundary-the length of the projection to x xpointrightbound = XBOTTOMRIGHTBOUND-XPROJL;                    Boundary plus an offset xpointleftbound + = OFFX;                                       Xpointrightbound + = OFFX;                        If the point is within the area if (uv.x > Xpointleftbound && uv.x < Xpointrightbound) {                                               Get the center point of the glowing area float midness = (xpointleftbound + xpointrightbound)/2;  The degree to which the center point is approaching, 0 means at the edge, 1 is at the center point Float rate= (Xlength-2*abs (uv.x-       midness))/(Xlength);                 brightness = rate;                               }} brightness= max (brightness,0);                return color = Pure white * Brightness float4 col = float4 (1,1,1,1) *brightness;            return brightness;                                 } float4 Frag (v2f i): COLOR {float4 outp;                       Obtain texture color according to UV, as usual float4 Texcol = tex2d (_MAINTEX,I.UV);                Pass into I.UV and other parameters, get the brightness value of float tmpbrightness;                           Tmpbrightness =inflash (75,i.uv,0.25f,5f,2f,0.15,0.7f); Image area, the decision is set to color a > 0.5, the output is a material color + light value if (TEXCOL.W >0.5) outp =texcol+float4 (                , *tmpbrightness);                Blank area, the decision is set to a <=0.5 color, output blank else outp =float4 (0,0,0,0);            return OUTP; } ENDCG}}}

  

Unity3d Tutorial Shader article: Fifth, the logo flash effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.