Plasma

glint · Examples · Tutorials · Gallery

The demoscene classic: layered sine fields through a cosine palette.

Plasma: a GLSL shader

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.

The code

One pass, in GLSL.

fragment shader

#version 300 es
precision highp float;

uniform float time;
uniform vec2 resolution;
uniform float speed;
uniform float scale;

in vec2 v_texcoord;
out vec4 fragColor;

vec3 palette(float t) {
    return 0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.1, 0.2)));
}

void main() {
    vec2 p = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y * scale;
    float t = time * speed;
    float v = sin(p.x + t);
    v += sin((p.y + t) * 0.5);
    v += sin((p.x + p.y + t) * 0.5);
    vec2 c = p + 0.5 * vec2(sin(t / 3.0), cos(t / 2.0));
    v += sin(sqrt(dot(c, c) + 1.0) + t);
    fragColor = vec4(palette(v * 0.25 + t * 0.05), 1.0);
}

More Starters examples

Vertex art · Lit mesh · Webcam kaleidoscope · Shadertoy style · Tunnel · Mandelbrot & Julia · Reaction–diffusion · Game of Life