欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Unity3DShader如何實(shí)現(xiàn)流光效果-創(chuàng)新互聯(lián)

這篇文章主要為大家展示了Unity3D Shader如何實(shí)現(xiàn)流光效果,內(nèi)容簡(jiǎn)而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會(huì)有收獲的,下面讓小編帶大家一起來(lái)看看吧。

成都創(chuàng)新互聯(lián)是一家專業(yè)提供當(dāng)涂企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、H5建站、小程序制作等業(yè)務(wù)。10年已為當(dāng)涂眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。

流光效果圖:

Unity3D Shader如何實(shí)現(xiàn)流光效果

演示工程:下載地址

//功能需求:模擬數(shù)據(jù)傳送效果,高亮色塊從模型上方移動(dòng)到下方
//功能分析:這里采用UV動(dòng)畫的方式來(lái)實(shí)現(xiàn),利用Alpha貼圖控制流動(dòng)的形狀
//  利用Alpha遮罩貼圖,控制模型中哪些地方需要進(jìn)行流動(dòng)

Shader "Custom/DataFlowEffect"
{
 Properties
 {
 _MainColor("Main Color",Color) = (1,1,1,1)
 _MainTex("Main Texture",2D) = "white"{}
 _Specular("Specular",Color) = (1,1,1,1)
 _Gloss("Gloss",Range(0,255)) = 20.0
 _FlowTex("Flow Tex (A)",2D) = "black"{}
 _FlowColor("Flow Color (RGBA)",Color)=(1,1,1,1)
 _FlowIdleTime("FlowInternal",Range(0,10))=1.0
 _FlowDuring("FlowDuring",Range(0,10))=1.0
 _FlowMaskTex("FlowMasking (A)",2D)="white"{}
 _FlowDirection("FlowDirection",Int)= 0
 _FlowBeginTime("Flow Begin Time",Float)=0
 }

 SubShader
 {
 Tags{"RenderType" = "Opaque" "Queue"="Geometry"}

 Pass
 {
  Tags{"LightMode"="ForwardBase"}
  Blend SrcAlpha OneMinusSrcAlpha

  CGPROGRAM

  #pragma vertex vert
  #pragma fragment frag

  #include "UnityCG.cginc"
  #include "Lighting.cginc"

  sampler2D _MainTex; //顏色貼圖
  half4 _MainTex_ST; //顏色UV 縮放和偏移
  fixed3 _MainColor; //漫反射顏色
  fixed3 _Specular; //高光顏色
  fixed _Gloss;  //高光度
  sampler2D _FlowTex; //數(shù)據(jù)流圖片
  fixed4 _FlowColor; //數(shù)據(jù)流顏色疊加
  half4 _FlowTex_ST; //數(shù)據(jù)流貼圖UV的縮放和偏移
  fixed _FlowIdleTime; //流動(dòng)動(dòng)畫間歇時(shí)間
  fixed _FlowDuring; //流動(dòng)動(dòng)畫播放時(shí)間
  sampler2D _FlowMaskTex; //流動(dòng)遮罩
  fixed _FlowDirection; //流動(dòng)方向
  float _FlowBeginTime; //流動(dòng)效果開始的時(shí)間

  struct a2v
  {
  half4 pos: POSITION;
  half3 normal :NORMAL;
  half4 texcoord : TEXCOORD0;
  };

  struct v2f
  {
  half4 position : SV_POSITION;
  half2 uv : TEXCOORD0;
  half3 worldNormal : TEXCOORD1;
  half3 worldPos : TEXCOORD2;
  half2 flowUV : TEXCOORD3;
  };

  v2f vert(a2v i)
  {
  v2f v;
  v.position = UnityObjectToClipPos(i.pos);
  v.uv = i.texcoord * _MainTex_ST.xy + _MainTex_ST.zw;
  v.worldNormal = mul(unity_ObjectToWorld,i.normal);
  v.worldPos = mul(unity_ObjectToWorld,i.pos);
  v.flowUV = i.texcoord * _FlowTex_ST.xy + _FlowTex_ST.zw;
  return v;
  }

  //uv - vert的uv坐標(biāo)
  //scale - 貼圖縮放
  //idleTime - 每次循環(huán)開始后多長(zhǎng)時(shí)間,開始流動(dòng)
  //loopTime - 單次流動(dòng)時(shí)間
  fixed4 getFlowColor(half2 uv,int scale,fixed idleTime,fixed loopTime)
  {
  //當(dāng)前運(yùn)行時(shí)間
  half flowTime_ = _Time.y - _FlowBeginTime;

  //上一次循環(huán)開始,到本次循環(huán)開始的時(shí)間間隔
  half internal = idleTime + loopTime;

  //當(dāng)前循環(huán)執(zhí)行時(shí)間
  half curLoopTime = fmod(flowTime_,internal);

  //每次開始流動(dòng)之前,有個(gè)停止間隔,檢測(cè)是否可以流動(dòng)了
  if(curLoopTime > idleTime)
  {
   //已經(jīng)流動(dòng)時(shí)間
   half actionTime = curLoopTime - idleTime;

   //流動(dòng)進(jìn)度百分比
   half actionPercentage = actionTime / loopTime;

   half length = 1.0 / scale;

   //從下往上流動(dòng)
   //計(jì)算方式:設(shè):y = ax + b,其中y為下邊界值,x為流動(dòng)進(jìn)度
   //根據(jù)我們要求可以,x=0時(shí)y=-length;x=1時(shí)y=1;帶入解方程
   half bottomBorder = actionPercentage * (1+length) - length;
   half topBorder = bottomBorder + length;

   //從上往下流動(dòng)
   //求解方法與上面類似
   if(_FlowDirection < 0)
   {
   topBorder = (-1-length) * actionPercentage + 1 + length;
   bottomBorder = topBorder - length;
   }

   if(uv.y < topBorder && uv.y > bottomBorder)
   {
   half y = (uv.y - bottomBorder) / length;
   return tex2D(_FlowTex,fixed2(uv.x,y)); 
   }
  }

  return fixed4(1,1,1,0);
  }

  fixed4 frag(v2f v):SV_Target
  {
  //計(jì)算漫反射系數(shù)
  fixed3 albedo = tex2D(_MainTex,v.uv) * _MainColor;

  //計(jì)算環(huán)境光
  fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;


  fixed3 worldNormal = normalize(v.worldNormal);    //世界坐標(biāo)的法線方向
  fixed3 worldLightDir = normalize(UnityWorldSpaceLightDir(v.worldPos)); //世界坐標(biāo)的光照方向
  fixed3 worldViewDir = normalize(UnityWorldSpaceViewDir(v.worldPos)); //世界坐標(biāo)的視角方向

  //計(jì)算漫反射顏色,采用Half-Lambert模型
  fixed3 lightColor = _LightColor0.rgb;
  fixed3 diffuse = lightColor * albedo * max(0,0.5*dot(worldNormal,worldLightDir)+0.5);

  //計(jì)算高光,采用Blinn-Phone高光模型
  fixed3 halfDir = normalize(worldViewDir + worldLightDir);
  fixed3 specColor = _Specular * lightColor * pow(max(0,dot(worldNormal,halfDir)),_Gloss);

  //疊加流動(dòng)貼圖  
  fixed4 flowColor = getFlowColor(v.uv,_FlowTex_ST.y,_FlowIdleTime,_FlowDuring); 
  fixed4 flowMaskColor = tex2D(_FlowMaskTex,v.uv);

  //與遮罩貼圖進(jìn)行混合,只顯示遮罩貼圖不透明的部分
  flowColor.a = flowMaskColor.a * flowColor.a * _FlowColor.a;

  fixed3 finalDiffuse = lerp(diffuse,_FlowColor,flowColor.a);

  return fixed4(ambient + finalDiffuse+specColor,1);
  }

  ENDCG
 }
 }
 Fallback "Diffuse"
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

新聞標(biāo)題:Unity3DShader如何實(shí)現(xiàn)流光效果-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)網(wǎng)址:http://chinadenli.net/article40/cciheo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT網(wǎng)站內(nèi)鏈Google企業(yè)建站商城網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷型網(wǎng)站建設(shè)