[Shader] Logo Flash Effect

Source: Internet
Author: User



?? 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
??? {
??? ??? Alphatest 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;
??? ??? ??? };
??? ??? ???
??? ??? ??? //vertex functions 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 in the use of itsFragfunction, otherwise it is not recognized.
??? ??? ??? //Core: Calculation function, Angle,UV,of the Light beltxlength, interval, start time, offset, single cycle time
??? ??? ??? Float Inflash (float angle,float2 uv,float xlength,int interval,int beginTime, float offx, float looptime)
??? ??? ??? {
??? ??? ??? ??? //Luminance Value
??? ??? ??? ??? float brightness = 0;
??? ??? ??? ???
??? ??? ??? ??? //Tilt Angle
??? ??? ??? ??? float Angleinrad = 0.0174444 * ANGLE;
??? ??? ??? ???
??? ??? ??? ??? //Current Time
??? ??? ??? ??? float currenttime = _time.y;
??? ??? ???
??? ??? ??? ??? //get the start time of this light
??? ??? ??? ??? int currenttimeint = _time.y/interval;
??? ??? ??? ??? Currenttimeint *=interval;
??? ??? ??? ???
??? ??? ??? ??? //get the elapsed time of this light = Current Time - Start Time
??? ??? ??? ??? float currenttimepassed = currenttime-currenttimeint;
??? ??? ??? ??? if (currenttimepassed >begintime)
??? ??? ??? ??? {
??? ??? ??? ??? ??? //bottom left and right borders
??? ??? ??? ??? ??? float Xbottomleftbound;
??? ??? ??? ??? ??? float Xbottomrightbound;

??? ??? ??? ??? ??? //this point boundary
??? ??? ??? ??? ??? float Xpointleftbound;
??? ??? ??? ??? ??? float Xpointrightbound;
??? ??? ??? ??? ???
??? ??? ??? ??? ??? float x0 = currenttimepassed-begintime;
??? ??? ??? ??? ??? X0/= looptime;
??? ??? ???
??? ??? ??? ??? ??? //Set right Border
??? ??? ??? ??? ??? Xbottomrightbound = x0;
??? ??? ??? ??? ???
??? ??? ??? ??? ??? //set left Border
??? ??? ??? ??? ??? Xbottomleftbound = X0-xlength;
??? ??? ??? ??? ???
??? ??? ??? ??? ??? //Projecting toxthe length= Y/tan (angle)
??? ??? ??? ??? ??? float XPROJL;
??? ??? ??? ??? ??? Xprojl= (UV.Y)/tan (Angleinrad);

??? ??? ??? ??? ??? //The left edge of this point = bottom left Border - Projecting toxthe length
??? ??? ??? ??? ??? Xpointleftbound = XBOTTOMLEFTBOUND-XPROJL;
??? ??? ??? ??? ??? //The right edge of this point = Bottom Right Border - Projecting toxthe length
??? ??? ??? ??? ??? Xpointrightbound = XBOTTOMRIGHTBOUND-XPROJL;
??? ??? ??? ??? ???
??? ??? ??? ??? ??? //boundary plus an offset
??? ??? ??? ??? ??? Xpointleftbound + = OFFX;
??? ??? ??? ??? ??? Xpointrightbound + = OFFX;
??? ??? ??? ??? ???
??? ??? ??? ??? ??? //If the point is within the region
??? ??? ??? ??? ??? 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,0represents at the edge,1indicates at 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;
??? ??? ??? ????
??? ??? ??? ???? //according toUVget the texture color, as usual
??? ??? ??? ??? FLOAT4 Texcol = tex2d (_MAINTEX,I.UV);
??? ???
??? ??? ??? ??? //Pass inI.uvequal parameters to get the luminance value
??? ??? ??? ??? float tmpbrightness;
??? ??? ??? ??? Tmpbrightness =inflash (75,i.uv,0.25f,5f,2f,0.15,0.7f);
??? ??? ???
??? ??? ??? ??? //image area, the decision is set toColor ofA > 0.5,output as material color+Light Value
??? ??? ??? ??? if (TEXCOL.W >0.5)
??? ??? ??? ??? ??? ??? Outp? =TEXCOL+FLOAT4 (1,1,1,1) *tmpbrightness;
??? ??? ??? ??? //Blank area, the decision is set toColor ofA <=0.5,Output Blank
??? ??? ??? ??? Else
??? ??? ??? ??? ??? OUTP =float4 (0,0,0,0);

??? ??? ??? ??? return OUTP;
??? ??? ??? }
??? ??? ??? Endcg
??? ??? }
??? }
}

reproduced from Wind Yu Chong unity3d Tutorial College

[Shader] 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.