Advertisement
Guest User

Untitled

a guest
Jan 29th, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Godot GLSL 1.59 KB | Source Code | 0 0
  1. // Author:
  2. // Title:
  3.  
  4. #ifdef GL_ES
  5. precision mediump float;
  6. #endif
  7.  
  8. uniform vec2 u_resolution;
  9. uniform vec2 u_mouse;
  10. uniform float u_time;
  11.  
  12. float random (vec2 st) {
  13.     return fract(sin(0.00175*3.14 + dot(st.xy,
  14.                                                 vec2(12.9898,78.233)))*
  15.             43758.5453);
  16. }
  17.  
  18. void main() {
  19.     vec2 uv = gl_FragCoord.xy/u_resolution.xy;
  20.     // to make it maintain the same scale for all resolutons (probably)
  21.     // uv.x *= u_resolution.x/u_resolution.y;
  22.    
  23.     // count of squares
  24.     float count = 3.0;
  25.     // so every square behaves like original UV
  26.     vec2 cell = fract(uv * count);
  27.    
  28.     // Angle vector, just for getting different rotation
  29.     // angle for every square.
  30.     vec2 angle_v = ceil(uv*count); // it will be (0,1), (2,1), etc
  31.    
  32.     float angle = 0.0;
  33.    
  34.     // trying to get 1D value from 2D vector
  35.     angle = (angle_v.x + angle_v.y);
  36.    
  37.     // angle = random(angle_v);
  38.     // if (angle <= 0.25) {
  39.     //     angle = 0.0;
  40.     // } else if (angle <= 0.5) {
  41.     //     angle = 3.14 * 0.5;
  42.     // } else if (angle <= 0.75) {
  43.     //     angle = 3.14;
  44.     // } else {
  45.     //     angle = 3.14 * 1.5;
  46.     // }
  47.  
  48.     // animate angle    
  49.     angle *= sin(3.14*u_time*0.25);
  50.    
  51.     // rotate cell
  52.     // 1. translate to new origin
  53.     cell = (cell - 0.5);
  54.     // 2. rotate vector
  55.     cell = vec2(
  56.         cell.x*cos(angle) - cell.y*sin(angle)
  57.         , cell.x*sin(angle) + cell.y*cos(angle)
  58.     );
  59.     // 3. translate it back
  60.     cell += 0.5;
  61.        
  62.     vec3 color = vec3(0.);
  63.     color = vec3(cell.x,cell.y,0.0);
  64.  
  65.     gl_FragColor = vec4(color,1.0);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement