Skip to content

Instantly share code, notes, and snippets.

@CharStiles
Created July 12, 2020 17:21
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 CharStiles/422ab3f47412d68fa94adab44decdacb to your computer and use it in GitHub Desktop.
Save CharStiles/422ab3f47412d68fa94adab44decdacb to your computer and use it in GitHub Desktop.
// http://www.iquilezles.org/www/articles/palettes/palettes.htm
// As t runs from 0 to 1 (our normalized palette index or domain),
//the cosine oscilates c times with a phase of d.
//The result is scaled and biased by a and b to meet the desired constrast and brightness.
vec3 cosPalette( float t, vec3 a, vec3 b, vec3 c, vec3 d )
{
return a + b*cos( 6.28318*(c*t+d) );
}
void main () {
// we put the pixel coordinates in a variable for easy access
vec2 pos = uvN();
// each chanel of the vec 3 corresponds to a color chanel
// red, green, blue!
vec3 brightness = vec3(0.5,0.5,0.5);
vec3 contrast = vec3(0.2,sin(time)*0.2,cos(time)*0.2);
vec3 osc = vec3(0.2); // how frequently we cycles through the colors
vec3 phase = vec3(0.5); // where does it start?
// getting the cosine palette
vec3 cp = cosPalette((time/1.0) +pos.x, brightness, contrast, osc, phase );
// casting the cosinePalette into a vector 4 by adding a 1 at the end
// the last number doesnt matter
vec4 col = vec4(cp,1);
// this is the bonus part!! this offsets where we grab the webcam pixel
// we offset the pixel using the force's snoise function, which returns
// a number that smoothly but randomly goes between -1 and 1, we can
// make it change through time by putting time as the last varible
// we get noise at the pixel in the pos
float whow = (snoise(vec3(pos,time)))* 0.1 ; // we scale it down
// access the webcam texture at the input pixels position
// multiplied times 1 + a small number, which returns a number
// close to its original but modified slightly.
vec4 web =texture2D(channel0,pos * (1.0 + whow));
// we get the backbuffer texture but slightly offset, 0.01 above the pixel
// position so it has this trailing up or slitscan effect.
vec4 prev = texture2D(backbuffer, pos - vec2(0, 0.01 ));
// mix is a GLSL function thats like mixing paint. We mix between two
// numbers using the last varible. The last varible is assumed to
// be between 0 and 1. it indicates how much of each color
// we need, so like if the last varible is 0.5 it mixes them evenly.
col = mix(web+col,prev,1.- web );
// this line makes it so that the slitscan effect happens where the web is light
// I didnt like the effect by itself so I spent some time tweaking these last two
// lines, excuse the magic numbers here. Try changing them and see what they do!
// this first line is like the previos line but it blows out the prev texture
col = mix(col,prev,web*1.31 );
// this preserves some of the webcam information, so whatever object is still
// recognizable
col = min(max(col,prev), web+ 0.3 );
// These lines are for the inverted effect, the backbuffer and coloring
// effect the dark parts of the picture more. Please comment out the two lines
// above and comment these in (ctl /) I provide this option because
// the effect is so dependent upon coloring, lighting, webcam white balance
// I dont want anyone to be stuck with an effect that doesnt have the
// desired effect on them.
//col = mix(col,prev,(web)*1.90 );
//col = mix(max(col,prev),web, web-0.15);
gl_FragColor = col ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment