Daily Creative Coding

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

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

See the Pen scaled checker pattern 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);
  mat2 scale = mat2(u_mouse.x / u_resolution.x * 5.0, 0.0,
                    0.0, u_mouse.y / u_resolution.y * 5.0);
  st = scale * st;

  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:20170406080137p:plain