Created
April 26, 2020 02:41
-
-
Save CharStiles/907ac57d078c921db4f2110991631662 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
// Example Pixel Shader | |
// uniform float exampleUniform; | |
out vec4 fragColor; | |
uniform float time; | |
float circ(vec2 p){ | |
return length(p) - .50; | |
} | |
// 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; | |
} | |
// 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) ); | |
} | |
float sdBox( in vec2 p, in vec2 b ) | |
{ | |
vec2 d = abs(p)-b; | |
return length(max(d,vec2(0))) + min(max(d.x,d.y),0.0); | |
} | |
void main() | |
{ | |
//gl_FragColor = vec4(black,1.0); | |
// VEC review | |
// float v = 0.50; | |
// vec2 v2 = vec2(0.2,0.4); | |
// vec3 v3 = vec3(v2,0.3); | |
// gl_FragColor = vec4(v3,v); | |
// moving UV position | |
// vec2 position = (uv() + 1.)/2.0 ; | |
//gl_FragColor = vec4(position,0,1.); | |
// distance metric | |
vec2 position = vUV.st; | |
position = position + vec2(sin(time),0); | |
pMod2(position, vec2(1)); | |
float shape = circ( position * vec2(3.0)); | |
position = position + vec2(cos(time),0); | |
float shape2 = sdBox(position, vec2(0.1)); | |
shape = min(shape,shape2); | |
//gl_FragColor = vec4(shape); | |
vec3 col = cosPalette(0.5,vec3(0.1),vec3(0.3),vec3(1),vec3(time*0.01,time*0.1,time*.2)); | |
// gl_FragColor = vec4(col,1.0); | |
// lighting: darken at the center | |
col = vec3(shape) * col; | |
//gl_FragColor = vec4(col,1.0); | |
fragColor = TDOutputSwizzle(vec4(col,1.0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment