Created
July 26, 2018 09:56
-
-
Save haschdl/539a694f7e508934ea3cb125d1a62194 to your computer and use it in GitHub Desktop.
[ShaderToy] Basic Voronoi
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
/* | |
* Voronoi visualization | |
* Copy of the first approach by @The_ArtOfCode, shown at https://www.youtube.com/watch?v=l-07BXzNdPw | |
* | |
* 27.07.2018 | |
*/ | |
vec2 N22(vec2 p) { | |
vec3 a = fract(p.xyx*vec3(123.34,234.34,345.65)); | |
a += dot(a, a+34.45); | |
return fract(vec2(a.x*a.y, a.y * a.z)); | |
} | |
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
// Normalized pixel coordinates (from 0 to 1) | |
float ar = iResolution.x/iResolution.y; | |
vec2 uv = (2. * fragCoord - iResolution.xy)/iResolution.y; | |
float m = 0.; | |
float t = iTime; | |
float minDist = 100.; | |
for(float i=0.; i<50.; i++) { | |
vec2 n = N22(vec2(i)); | |
vec2 p = sin(n*t); | |
p.x *= ar; //aspect ratio | |
float d = length(uv-p); | |
m+= smoothstep(.02, .01,d); | |
if(d<minDist) { | |
minDist = d; | |
} | |
} | |
// Time varying pixel color | |
vec3 col = vec3(minDist); | |
// Output to screen | |
fragColor = vec4(col,1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment