Skip to content

Instantly share code, notes, and snippets.

@solsarratea
Created June 9, 2020 02:06
Show Gist options
  • Save solsarratea/e46a387da92d9a47fe00fc8f97bc77e6 to your computer and use it in GitHub Desktop.
Save solsarratea/e46a387da92d9a47fe00fc8f97bc77e6 to your computer and use it in GitHub Desktop.
Simple plane folding
// Create foldings
// Target: flip one of the sides into another.
// i - For each point on on of the side reflect point around an arbitrary line.
void main (){
vec2 pos = uv();
vec4 color = vec4(0.);
//Starting (i)
vec2 normal; float angle; float dist;
// angle = PI/3.;
angle = mouse.x *0.1;
//Defining normal
normal = vec2(sin(angle),cos(angle));
dist = dot(pos, normal);
//Walk towards the line -> need sign! eventually need only one side for flipping; either min max should work (flips neg pos respectively)
pos -= normal*min(dist,0.);
//We need 2 steps one to the line, another to the other side.
pos -= normal*min(dist,0.);
//Drawing line
dist = abs(dist);
dist = 1.-smoothstep(0.001,0.01,dist);
color += dist;
color.rb += sin(pos*20.);
gl_FragColor = color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment