Created
July 12, 2020 17:36
-
-
Save CharStiles/78c1a0ac6b51cce832efb7bb6a43d1f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// 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); | |
// 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 | |
gl_FragColor = col ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment