Created
June 9, 2020 03:55
-
-
Save solsarratea/d8745065e623fe355bf00357e2a94a4d to your computer and use it in GitHub Desktop.
Koch snowflake
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
// Kosh snowflake | |
const int iterations = 5; | |
float scale = 3.; | |
float reflection(inout vec2 pos, float angle){ | |
vec2 normal = vec2(sin(angle),cos(angle)); | |
float d = dot(pos, normal); | |
pos -= normal*min(0.,d)*2.; | |
return smoothstep(0.01,0.,abs(d)); | |
} | |
float line (vec2 pos){ | |
float d = length(pos-vec2(clamp(pos.x,-1.,1.),0.)); | |
return smoothstep(0.001,0.,abs(d)/pow(scale, float(iterations))); | |
} | |
void main() { | |
vec2 pos = uv(); | |
//pos*=1./3.; | |
//pos.x +=.5; | |
pos.x = -abs(pos.x); | |
vec4 color = vec4(0.); | |
float angle = PI*2./3.; | |
pos += vec2(.5,-.25); | |
float l = reflection(pos , PI-PI*5./6.); | |
color += l*vec4(0.,1.,0.,1.); | |
// Recover uv values; Repeat it over segments; | |
for (int i =0; i< iterations;i++){ | |
pos *= scale; //scale | |
pos.x -= 1.5; //transalte | |
pos.x = abs(pos.x); | |
pos.x -= .5; | |
reflection(pos,angle); | |
} | |
color += line(pos); | |
//color.rb += pos; | |
gl_FragColor = color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment