Skip to main content

1 GLSL

1.1 Tool to test GLSL

Browser doesn't support HTML5 canvas.

Vertex shader:

#version 100
uniform float u_rotate;
uniform vec4 u_color;
uniform vec2 u_aspect;
uniform vec2 u_mouse;
uniform float u_time;

attribute vec2 position;
attribute vec2 texel;

varying vec4 color;
varying vec2 st;
//varying float time;

void main() {
  gl_PointSize = 5.0;

  vec2 p = position * u_aspect * 2.0 - 1.0; // aspect is inverted; x,y on [-1, 1]

  vec2 u = vec2(1.0, u_rotate);
  vec2 z = vec2(1.0-u_rotate*u_rotate, 2.0*u_rotate) / dot(u,u);
  // complex multiplication z*p (mat2 is column-major)
  // p = vec2(z.x*position.x - z.y*position.y, z.x*position.y + z.y*position.x);
  mat2 rot = mat2(z.x, z.y, -z.y, z.x);

  gl_Position = vec4(rot*p, -1.0, 1.0);

  color = u_color;
  st = vec2(texel.x, 1.0-texel.y); // s & t on [0,1]
  //time = u_time;
}

Fragment shader:

#version 100
precision mediump float;
uniform sampler2D u_sampler;
uniform vec2 u_dimensions;
varying vec4 color;
varying vec2 st;
// varying vec2 time;

void main() {
  vec2 p = gl_FragCoord.xy * u_dimensions;
  gl_FragColor = vec4(p, 1.0, 1.0);

  // gl_FragColor = color;
  // gl_FragColor = texture2D(u_sampler, st);
}