欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

OpenGL Shader实例分析(3)等待标识效果

程序员文章站 2022-06-16 15:14:17
本文实例为大家分享了opengl shader实例,等待标识,不过效率估计不是很高。结果如下: 代码: shader "stalendp/waiticons...

本文实例为大家分享了opengl shader实例,等待标识,不过效率估计不是很高。结果如下:

OpenGL Shader实例分析(3)等待标识效果

代码:

shader "stalendp/waiticons" { 
  cginclude  
  
  #include "unitycg.cginc"     
  #pragma target 3.0  
  struct v2f {  
   float4 pos:sv_position;  
   float2 uv : texcoord0;  
  };  
  
  v2f vert(appdata_base v) {  
   v2f o; 
   o.pos = mul (unity_matrix_mvp, v.vertex); 
   o.uv = v.texcoord.xy; 
   return o;  
  }  
  
  fixed calcdot(fixed a, fixed ca, fixed2 uv) {
   a /= 57.295779513;
   ca /= 57.295779513;
   fixed tt = 180/57.295779513;
   uv = (fixed2(cos(a), sin(a)) * 0.2+ uv)*10;
   fixed adit = tt*2*step(tt, a-ca);
   fixed r = 1-step(ca + adit, a);
   r *= lerp(0.2, -1, saturate((ca-a+adit)/25))*2;
   return smoothstep(r-0.2, r, length(uv.xy));
  }
  
  fixed4 frag(v2f input) : color0 {  
   float2 uv = input.uv.xy - float2(0.5); 
   float rx = fmod(uv.x, 0.4); 
   float ry = fmod(uv.y, 0.4); 
   float mx = step(0.4, abs(uv.x)); 
   float my = step(0.4, abs(uv.y)); 
   float alpha = 1- mx*my*step(0.1, length(half2(rx,ry))); 
   alpha*=0.9; 
   
   fixed4 forecolor = fixed4(1);
   fixed4 bgcolor = fixed4(fixed3(0.4),alpha);
   fixed4 result = bgcolor;
   
   fixed ca = fmod(_time.y, 2)*180;
   
 bgcolor = lerp(forecolor, bgcolor, calcdot(0, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(30, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(60, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(90, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(120, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(150, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(180, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(210, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(240, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(270, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(300, ca, uv));
 bgcolor = lerp(forecolor, bgcolor, calcdot(330, ca, uv));
   
   return bgcolor; 
  }  
 endcg  
  
 subshader {  
  lod 200 
  tags {"queue" = "transparent"} 
  zwrite off 
  blend srcalpha oneminussrcalpha  
  pass {  
   cgprogram  
  
   #pragma vertex vert  
   #pragma fragment frag  
   #pragma fragmentoption arb_precision_hint_fastest   
  
   endcg  
  }  
  
 }   
 fallback off  
} 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。