Created
July 13, 2019 20:18
-
-
Save mrange/147b50e2845ec7d9ea06a6c0c1d3ce43 to your computer and use it in GitHub Desktop.
2d 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
#version 150 | |
in VertexData | |
{ | |
vec4 v_position; | |
vec3 v_normal; | |
vec2 v_texcoord; | |
} inData; | |
out vec4 fragColor; | |
//////////////////////////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////////////////////////// | |
uniform vec2 iResolution; | |
uniform float iTime; | |
uniform float iTimeDelta; | |
uniform int iFrame; | |
uniform vec4 iMouse; | |
uniform sampler2D iChannel0; | |
uniform sampler2D iChannel1; | |
uniform sampler2D iChannel2; | |
uniform sampler2D iChannel3; | |
uniform vec4 iDate; | |
uniform float iSampleRate; | |
void mainImage(out vec4, in vec2); | |
void main(void) { mainImage(fragColor,inData.v_texcoord * iResolution.xy); } | |
//////////////////////////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////////////////////////// | |
const float Size = 7; | |
const float Scale = 2; | |
const vec3 plnormal = normalize(vec3(1, 1, -1)); | |
#define Phi (.5*(1.+sqrt(5.))) | |
const vec3 n1 = normalize(vec3(-Phi,Phi-1.0,1.0)); | |
const vec3 n2 = normalize(vec3(1.0,-Phi,Phi+1.0)); | |
const vec3 n3 = normalize(vec3(0.0,0.0,-1.0)); | |
float de(in vec3 z) | |
{ | |
float t; | |
// Folds. | |
//Dodecahedral.. you can use other sets of foldings! | |
z = abs(z); | |
t=dot(z,n1); if (t>0.0) { z-=2.0*t*n1; } | |
t=dot(z,n2); if (t>0.0) { z-=2.0*t*n2; } | |
z = abs(z); | |
t=dot(z,n1); if (t>0.0) { z-=2.0*t*n1; } | |
t=dot(z,n2); if (t>0.0) { z-=2.0*t*n2; } | |
z = abs(z); | |
//combine DEs... explore different combinations ;) | |
//the base DE is the distance to the plane going through vec3(Size,0.,0.) and which normal is plnormal | |
float dmin=dot(z-vec3(Size,0.,0.),plnormal); | |
// Rotate, scale, rotate (we need to cast to a 4-component vector). | |
return (dmin);//you can take a look to the inside | |
} | |
void mainImage(out vec4 fragColor, in vec2 fragCoord) | |
{ | |
vec2 uv = fragCoord.xy / iResolution.xy; | |
uv = 2.0*(uv - 0.5); | |
uv.x *= iResolution.x/iResolution.y; | |
float d = de(vec3(uv*7, 7.0*sin(0))); | |
vec3 col = abs(d) < 0.01 ? vec3(1.0) : vec3(0.0); | |
fragColor = vec4(col,1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment