Created
July 30, 2022 16:23
-
-
Save CharStiles/556d5d78930532c1a7910eb124d33a5f to your computer and use it in GitHub Desktop.
This file contains 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 | |
// to see this function graphed out go to: https://www.desmos.com/calculator/rz7abjujdj | |
vec3 cosPalette( float t , vec3 brightness, vec3 contrast, vec3 osc, vec3 phase) | |
{ | |
return brightness + contrast*cos( 6.28318*(osc*t+phase) ); | |
} | |
void main() { | |
vec2 pos = ((gl_FragCoord.xy/resolution) - 0.5)*2.0; // origin is in center | |
// who remembers SOH CAH TOA ? | |
// tan, given an angle will return the ratio | |
// so if we only have the ratio of position | |
// we use atan to get the angle | |
float angle = atan(pos.y,pos.x); | |
float r = sin(angle + time); | |
// sin returns a number from -1 to 1, and colors are from 0 to 1, so thats | |
// why you only see red on the screen half the time. the angle goes around | |
// the screen, adding time moves it clockwise | |
float ringFrequency = 5.; // making this number bigger will increase frequency | |
float g = cos(length(pos*ringFrequency) - time); | |
// the distance (aka length) from the center put in a cos, time moves the | |
// circles in. | |
float b = cos(angle+ cos(length(pos*ringFrequency *3.))); | |
// this combines what we learned in the red and green channels | |
// angle is going through a cos and so is the length, so we see the | |
// blue channel oscillating in both dimensions the polar coordinates give us | |
// please play around with these numbers to get a better palette | |
vec3 brightness = vec3(0.5); | |
vec3 contrast = vec3(0.2); | |
vec3 osc = vec3(r); | |
vec3 phase = vec3(g, cos(time/23.), sin(time/31.)); | |
vec3 color = cosPalette(b, brightness, contrast, osc, phase); | |
// add some variance | |
color -= sin(pos.x*40. + time)*0.5; | |
// get the backbuffer | |
vec4 prevFrame = texture2D(backbuffer, (gl_FragCoord.xy/resolution) - pos*0.01); | |
//convert color to vec4 | |
vec4 finalCol = vec4(color,1.); | |
// mix them with the final parameter being how much of each of the first two parameters to mix | |
// so 0 would be all the first parameter and 1 would be all the second. | |
// make the second color purple and play around with the last parameter to get a feel for this function | |
finalCol = mix(finalCol, prevFrame, clamp(g,0.,1.)); | |
gl_FragColor = finalCol; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment