Created
June 9, 2020 02:06
-
-
Save solsarratea/e46a387da92d9a47fe00fc8f97bc77e6 to your computer and use it in GitHub Desktop.
Simple plane folding
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
// 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