Skip to content

Instantly share code, notes, and snippets.

@JBlackCat
Created March 28, 2017 21:41
Show Gist options
  • Save JBlackCat/69997ecd57db925ad3ddf928e3a83b87 to your computer and use it in GitHub Desktop.
Save JBlackCat/69997ecd57db925ad3ddf928e3a83b87 to your computer and use it in GitHub Desktop.
Bouncing color gradient columns
//Base on Tutorial #17, https://www.shadertoy.com/view/Md23DV
#define PI 3.14159265359
void main() {
//coordinate systems
vec2 r = vec2((gl_FragCoord.xy - 0.5*resolution.xy)/resolution.y) * 2.0; // Is [-1, 1] coordinate system
vec2 p = vec2(gl_FragCoord.xy/resolution.xy); //[0,1] coordinate system
//Set background color
vec3 bgCol = vec3(0.0); // black
vec3 pixel = bgCol;
vec3 rAxesColor = vec3(0.537, 1.0, 0.364);
float rAxesThickness = 0.006;
vec3 pAxesColor = vec3(1.0, 0.412, 0.635);
float pAxesThickness = 0.008;
// -----------------------------------
// ------------ Start ----------------
vec3 col1 = vec3(0.216, 0.471, 0.698); // blue
vec3 col2 = vec3(1.00, 0.329, 0.298); // red
vec3 col3 = vec3(0.867, 0.910, 0.247); // yellow
float item0;
float item1;
float pctMix;
float mixedVal;
vec3 ret;
if(p.x < 1.0/5.0){
pctMix = smoothstep(0.25*abs(1.5*sin(time)+0.25), 0.75*abs(1.5*sin(time)+0.25), p.y);
ret = mix(col1, col2, pctMix);
}
else if(p.x < 2.0/5.0) { // Part II
pctMix = smoothstep(0.25*abs(2.0*sin(time)+0.5), 0.75*abs(2.0*sin(time)+0.5), p.y);
ret = mix(col1, col2, pctMix);
}
else if(p.x < 3.0/5.0) {
pctMix = smoothstep(0.25*abs(0.65*sin(time)+0.75), 0.85*abs(0.5*sin(time)+0.75), p.y);
ret = mix(col1, col2, pctMix);
}
else if(p.x < 4.0/5.0){
pctMix = smoothstep(0.25*abs(sin(time)+1.25), 0.75*abs(sin(time)+1.25), p.y);
ret = mix(col1, col2, pctMix);
}
else {
pctMix = smoothstep(0.15*abs(sin(time)), 0.95*abs(sin(time)), p.y);
ret = mix(col1, col2, pctMix);
}
pixel = vec3(ret);
// ------------- End -----------------
// -----------------------------------
//[0,1] coordinat system axes
if(abs(p.x) < pAxesThickness) pixel = pAxesColor;
if(abs(p.y) < pAxesThickness) pixel = pAxesColor;
//[-1,1] coordinat system axes
// if(abs(r.x) < rAxesThickness) pixel = rAxesColor;
// if(abs(r.y) < rAxesThickness) pixel = rAxesColor;
//Final output
gl_FragColor = vec4(pixel, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment