Advertisement
mivebe

Ex: 4 - Rotation

Nov 21st, 2023 (edited)
1,482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 300 es
  2. #ifdef GL_ES
  3. precision mediump float;
  4. #endif
  5.  
  6. uniform vec2 u_resolution;
  7. uniform float u_time;
  8. out vec4 outColor;
  9.  
  10. float rectShape(vec2 position, vec2 scale) {
  11.   scale = vec2(0.5) - scale * 0.5;
  12.   vec2 shaper = vec2(step(scale.x, position.x), step(scale.y, position.y));
  13.   shaper *= vec2(step(scale.x, 1.0 - position.x), step(scale.y, 1.0 - position.y));
  14.   return shaper.x * shaper.y;
  15. }
  16.  
  17. mat2 rotate(float angle) {
  18.   return mat2(cos(angle), - sin(angle), sin(angle), cos(angle));
  19. }
  20.  
  21. void main() {
  22.   vec2 coord = gl_FragCoord.xy / u_resolution.x;
  23.   vec3 color = vec3(0.0);
  24.  
  25.   coord -= vec2(0.5);
  26.   coord = rotate(0.5 * sin(u_time)) * coord;
  27.   coord += vec2(0.5);
  28.  
  29.   color += vec3(rectShape(coord, vec2(0.3, 0.3)));
  30.  
  31.   outColor = vec4(color, 1.0);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement