Skip to content

Instantly share code, notes, and snippets.

@funatsufumiya
Created August 10, 2014 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funatsufumiya/e8e995fc552c61deab13 to your computer and use it in GitHub Desktop.
Save funatsufumiya/e8e995fc552c61deab13 to your computer and use it in GitHub Desktop.
GLSL Gradient Shader with Processing
uniform float millis;
uniform float width;
uniform float height;
void main()
{
float rx = gl_FragCoord.x / width;
float ry = gl_FragCoord.y / height;
float rate = sin(millis)/2.0 + 0.5;
float rate_inv = 1.0 - rate;
gl_FragColor = vec4(rate * rx, rate_inv * ry, 0.0, 1.0);
}
PShader myShader;
void setup() {
size(640, 360, P3D);
myShader = loadShader("gradient.glsl");
fill(255);
noStroke();
myShader.set("width", (float)width);
myShader.set("height", (float)height);
}
void draw() {
// saveFrame("rec/####.png");
myShader.set("millis", millis()/1000.0);
shader(myShader);
background(0);
rect(0,0,width,height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment