Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

【GLSL】スケールするチェッカーパターン2

See the Pen scaled checker pattern 2 by aadebdeb (@aadebdeb) on CodePen.

#define PI 3.14159265359

precision mediump float;

uniform float u_time;
uniform vec2 u_mouse;
uniform vec2 u_resolution;

void main(void) {

  vec2 pos = gl_FragCoord.xy - u_resolution / 2.0;
  float size = 30.0;
  vec2 st = pos / (size * 2.0);

  float scale = distance(u_mouse, u_resolution / 2.0) / 100.0;
  float angle = atan(u_mouse.y, u_mouse.x);
  vec2 n = vec2(cos(angle), sin(angle));
  st = st + (scale - 1.0) * dot(st, n) * n;

  float c = abs(step(0.5, fract(st.x)) - step(0.5, fract(st.y)));

  gl_FragColor = vec4(vec3(c), 1.0);
}
f:id:aa_debdeb:20170406081126p:plain