Skip to content

Instantly share code, notes, and snippets.

@co3moz
Last active March 28, 2018 06:23
Show Gist options
  • Save co3moz/e49740d499e12330d0a2 to your computer and use it in GitHub Desktop.
Save co3moz/e49740d499e12330d0a2 to your computer and use it in GitHub Desktop.
just glsl starter boilerplate :)
precision mediump float;
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
void main() {
vec2 aspect = resolution.xy / min(resolution.x, resolution.y);
vec2 position = (gl_FragCoord.xy / resolution.xy) * aspect;
vec4 color = vec4(0.0);
gl_FragColor = color;
}
@co3moz
Copy link
Author

co3moz commented Feb 26, 2016

Spiral Tube
Buffer example

precision mediump float;
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
uniform sampler2D buffer;

void rotate(out vec2 position, float angle) {
    float px = position.x;
    position.x = px * cos(time) - position.y * sin(time);
    position.y = px * sin(time) + position.y * cos(time);
}

vec4 loadColorFromBuffer(vec2 position, vec2 aspect, vec2 shift) {
    return texture2D(buffer, position / aspect + shift);
}

void main() {
    vec2 aspect = resolution.xy / min(resolution.x, resolution.y);
    vec2 position = (gl_FragCoord.xy / resolution.xy) * aspect;
    vec4 color = vec4(0.0);
    if (time > 1.0) {
        #define load(x, y) loadColorFromBuffer(position, aspect, vec2(x, y))
        color = (load(0.001, 0.0) / load(-0.001, 0.0));
    }

    vec2 m = vec2(0.7 + sin(time) / 10.0, 0.5 + cos(time) / 10.0) * aspect;
    rotate(position, time);
    rotate(m, time);

    float size = 0.3;
    if (distance(m, position) < size) {
        float merge = 1.0 - distance(m, position) / size;

        if (m.y < position.y) {
            if (m.x > position.x) {
                color = vec4(merge, 0.0, 0.0, 1.0);
            } else {
                color = vec4(0.0, 0.0, merge, 1.0);
            }
        } else {
            if (m.x > position.x) {
                color = vec4(0.0, merge, 0.0, 1.0);
            } else {
                color = vec4(merge, merge, 0.0, 1.0);
            }
        }
    }

    gl_FragColor = color;
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment