Skip to content

Instantly share code, notes, and snippets.

@fand
Created August 28, 2020 04:01
Show Gist options
  • Select an option

  • Save fand/8c5a31eb544b35f2eb489c4fda8dea5d to your computer and use it in GitHub Desktop.

Select an option

Save fand/8c5a31eb544b35f2eb489c4fda8dea5d to your computer and use it in GitHub Desktop.
VEDA nested loop test
/*{
pixelRatio:0.5,
}*/
precision mediump float;
uniform float time;
uniform vec2 resolution;
#define PI 3.141593
vec2 rot(vec2 uv, float t) {
float c = cos(t), s = sin(t);
return mat2(c, -s, s, c) * uv;
}
float draw(vec2 p) {
float l = length(p);
// return clamp(.03 / abs(l - 0.5) * (1. + sin((p.x - p.y) * 100.) * 0.3), 0., 1.);
// return clamp(.03 / abs(l - 0.5) * (1. + sin((p.x) * 100.) * 0.3), 0., 1.);
return clamp(.1 / abs(p.y - sin(p.x *3. +time * 2.) * 2. -0.3) * (1. + sin((p.x) * 100.) * 0.3), 0., 1.);
}
vec2 tile(vec2 p) {
float a = atan(-p.y, -p.x) + PI;
float third = PI / 3.;
if (a > 5. * third) {
p = rot(p, 3. * third);
p.x *= -1.;
}
else if (a > 3. * third) {
p = rot(p, -2. * third);
}
else if (a > third) {
p = rot(p, -4. * third);
}
return p;
}
void main() {
vec2 p = (gl_FragCoord.xy * 2. - resolution) / min(resolution.x, resolution.y);
p *= 0.5;
p = tile(p);
p = rot(p, length(p) * 2.);
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++)
{
p = rot(p, float(i) * 0.003 + sin(time * 0.1) * 0.03);
p += float(j) * 0.003;// + sin(time * 0.03) * 0.01;
p = fract(p);
p = tile(p);
}
}
// p = tile(p);
gl_FragColor = vec4(
draw(p + vec2(0.01, 0)),
draw(p),
draw(p - vec2(0.01, 0)),
1.
);
// gl_FragColor = vec4(
// 0.3 / length(p + vec2(sin(time * 0.23) * 0.4, 0)),
// 0.3 / length(p + vec2(sin(time * 0.33) * 0.4, 0)),
// 0.3 / length(p + vec2(sin(time * 0.43) * 0.4, 0)),
// 1.
// );
}
@fand
Copy link
Copy Markdown
Author

fand commented Aug 28, 2020

It works
out2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment