Created
September 27, 2022 03:19
-
-
Save CharStiles/18398a29d4cb4cac07133f460b46ca48 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/18rq4ybrru | |
vec3 cosPalette( float t , vec3 brightness, vec3 contrast, vec3 osc, vec3 phase) | |
{ | |
return brightness + contrast*cos( 6.28318*(osc*t+phase) ); | |
} | |
// Repeat around the origin by a fixed angle. | |
// For easier use, num of repetitions is use to specify the angle. | |
float pModPolar(inout vec2 p, float repetitions) { | |
float PI = 3.14; | |
float angle = 2.*PI/repetitions; | |
float a = atan(p.y, p.x) + angle/2.; | |
float r = length(p); | |
float c = floor(a/angle); | |
a = mod(a,angle) - angle/2.; | |
p = vec2(cos(a), sin(a))*r; | |
// For an odd number of repetitions, fix cell index of the cell in -x direction | |
// (cell index would be e.g. -5 and 5 in the two halves of the cell): | |
if (abs(c) >= (repetitions/2.)) c = abs(c); | |
return c; | |
} | |
// Repeat in two dimensions | |
vec2 pMod2(inout vec2 p, vec2 size) { | |
vec2 c = floor((p + size*0.5)/size); | |
p = mod(p + size*0.5,size) - size*0.5; | |
return c; | |
} | |
float sdPentagon( in vec2 p, in float r ) | |
{ | |
const vec3 k = vec3(0.809016994,0.587785252,0.726542528); | |
p.x = abs(p.x); | |
p -= 2.0*min(dot(vec2(-k.x,k.y),p),0.0)*vec2(-k.x,k.y); | |
p -= 2.0*min(dot(vec2( k.x,k.y),p),0.0)*vec2( k.x,k.y); | |
return length(p-vec2(clamp(p.x,-r*k.z,r*k.z),r))*sign(p.y-r); | |
} | |
vec3 hsb2rgb(vec3 c) | |
{ | |
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | |
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | |
} | |
float sdCircle( vec2 p, float r ) | |
{ | |
return length(p) - r; | |
} | |
void main () { | |
vec2 pos = gl_FragCoord.xy/ resolution; | |
pos= (pos*2.)-1.; | |
pos.x *= resolution.x/resolution.y; | |
pModPolar(pos, 5.); | |
vec2 id = pMod2(pos, vec2(0.5,0.5)); | |
float angle = atan(pos.y,pos.x); | |
float r = (sin(angle +time)+1.)/2.; | |
float dist = length(pos); | |
float g = sin(dist*10.-time); | |
float b = sin( cos(angle*10.-dist*30. +time*3.) ); | |
vec3 brightness = vec3(0.9,0.8,0.98); | |
vec3 contrast = vec3(g,0.12*g,0.2*g); | |
vec3 phase = vec3(0.5,01.5,0.5); | |
vec3 osc = vec3(0.9*r,0.33*g,0.1); | |
float pent = sdPentagon(pos, sin(time)+1.0); | |
vec3 rainbow = hsb2rgb(vec3(r,b - g,0.5)); | |
vec3 color = cosPalette(pent, brightness+sin(id.x+id.y + time)*bands.z, contrast, osc, phase); | |
vec3 finalCol = color ; | |
gl_FragColor = vec4(finalCol-0.5,1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment