josemorval

Triangles rotation pattern

May 24th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float triDist(vec2 p){
  2.   float f = smoothstep(0.0,0.01,p.x-p.y);
  3.   f*=  smoothstep(0.0,0.01,-p.x-p.y);
  4.   f*=  smoothstep(0.0,0.01,0.5+p.y);
  5.   return f;
  6. }
  7.  
  8. void main(){
  9.   vec2 p = gl_FragCoord.xy/iResolution;
  10.   p-=0.5;
  11.   p.x *= iResolution.x/iResolution.y;
  12.   p*=20.0;
  13.  
  14.   float gridsize = 1.5;
  15.  
  16.   vec2 pcenter = floor((p)/gridsize);
  17.  
  18.   float angle = 1.0+iGlobalTime+sin(1.0*pcenter.x);
  19.   angle = angle;
  20.  
  21.   vec2 prot=mod(p,gridsize)-gridsize/2.0;
  22.   prot  = mat2(
  23.     cos(angle),
  24.     sin(angle),
  25.     -sin(angle),
  26.     cos(angle)
  27.   )*prot;
  28.  
  29.   vec2 ptrans = prot-vec2(0.0,0.0);
  30.   float f = triDist(ptrans);
  31.  
  32.   ptrans = mat2(
  33.     cos(3.14159/1.0),
  34.     sin(3.14159/1.0),
  35.     -sin(3.14159/1.0),
  36.     cos(3.14159/1.0)
  37.   )*prot;
  38.   ptrans = ptrans-vec2(0.0,-0.0);
  39.  
  40.   f = max(f,triDist(ptrans));
  41.  
  42.   float m = 0.5+0.5*sin(123.0*pcenter.x+5587.0*pcenter.y+3.0*iGlobalTime);
  43.   gl_FragColor = vec4(m*f,0.0,0.0,1.0);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment