Skip to content

Instantly share code, notes, and snippets.

@petersalomonsen
Last active December 19, 2021 20:23
Show Gist options
  • Save petersalomonsen/4d2f9208d28526baefec74f30d4387e5 to your computer and use it in GitHub Desktop.
Save petersalomonsen/4d2f9208d28526baefec74f30d4387e5 to your computer and use it in GitHub Desktop.
Fractals
#version 100
precision highp float;
uniform vec2 resolution;
uniform float time;
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main(){
#define product(a, b) vec2(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x)
#define PI 3.1415926538
float speed = -0.1;
float t = 0.3 * sin(PI * 3.0/2.0 + time * speed) + 2.1;
// t = 2.0;
float res = resolution.x > resolution.y ? resolution.x : resolution.y;
float scale = (6.0/pow(t,1.0 + t));
vec2 center = vec2(-0.5,-0.0022);
vec2 p = (gl_FragCoord.xy - resolution * 0.5) / res * scale;
float persp = 0.0015;
p = vec2(p.x * persp/ p.y, persp/p.y);
vec2 centerp = vec2(center.x * persp / center.y, persp / center.y);
vec2 z;
vec2 dc = p - center;
float radius = sqrt(p.x*p.x+p.y*p.y) / scale;
float rotation = time * 0.001;
p = p - centerp;
vec2 c = vec2(p.x*cos(rotation)-p.y*sin(rotation),p.x*sin(rotation)+p.y*cos(rotation));
float color = 0.0;
float max_iteration_float = exp(1.0 * sin(PI * 3.0/2.0) + t) * 30.0;
for (int iteration = 0;iteration < 1000;iteration++) {
z = product(z,z) + c;
color += 1.0;
if (color >= max_iteration_float) {
break;
}
if (z.x*z.x + z.y*z.y > 4.0) {
break;
}
}
p.xy = z;
color = (color / max_iteration_float);
vec3 rgb;
if (gl_FragCoord.y < resolution.y * 0.5) {
rgb = hsv2rgb(vec3(0.35 + color * 0.24,1.0 - sin(time * 0.5 + radius * 40.0) * 0.1, 0.3 + color * 0.7 + (color < 0.5 ? sin(p.x) * 0.05: 0.0 )));
} else {
rgb = hsv2rgb(vec3(0.57 + color * 0.1,1.0 - color * 0.9, 1.0 - color * 0.3 ));
}
gl_FragColor=vec4(rgb,1);
}
#version 100
precision highp float;
uniform vec2 resolution;
uniform vec2 mouse;
uniform float time;
uniform sampler2D backbuffer;
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main(){
#define product(a, b) vec2(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x)
#define PI 3.14159265358979323846
float speed = -0.1;
float t = 0.2 * sin(PI * 3.0/2.0 + time * speed) + 5.1;
float res = resolution.x > resolution.y ? resolution.x : resolution.y;
float scale = (6.0/pow(t,1.0 + t));
vec2 center = vec2(0.9962,-0.289);
vec2 p = (gl_FragCoord.xy - resolution * 0.5) / res * scale;
vec2 z;
float rotation = time * 0.05;
vec2 c = vec2(p.x*cos(rotation)-p.y*sin(rotation),p.x*sin(rotation)+p.y*cos(rotation)) - center;
float color = 0.0;
float max_iteration_float = exp(t) * 20.0;
for (int iteration = 0;iteration < 1000;iteration++) {
z = product(z,z) + c;
color += 1.0;
if (color >= max_iteration_float) {
break;
}
if (z.x*z.x + z.y*z.y > 4.0) {
break;
}
}
color = (color / max_iteration_float);
vec3 rgb = hsv2rgb(vec3(0.5 + 0.2 * color,1.0,color ));
vec2 descaled = vec2(sin(time) * 0.1, time * 0.2) +
vec2(0, 0.5 * sin(p.x * scale * res * 2.0 * pow(t,1.0 + t)))
+(p + center) * res * scale * 2.0 * pow(t,1.0 + t);
float modu = PI * 0.3;
vec2 modded = mod(descaled, modu) - modu * 0.5;
modded.x *= 2.0;
float dist = sqrt(modded.x*modded.x + 3.0 * modded.y * modded.y);
if (dist < PI) {
float snowamount = cos(dist);
float snowsize = 0.002;
if ( snowamount > 1.0 - snowsize ) {
float snowfactor = 0.2 * ((snowamount - (1.0 - snowsize)) / snowsize);
rgb = vec3(1.0,1.0,1.0) * snowfactor + rgb * (1.0 - snowfactor);
}
}
gl_FragColor=vec4(rgb,1);
}
#version 100
precision highp float;
uniform vec2 resolution;
uniform float time;
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main(){
#define product(a, b) vec2(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x)
#define PI 3.1415926538
float speed = -0.05;
float t = 2.5 * sin(PI * 3.0/2.0 + time * speed) + 3.2;
//t = 5.5;
float res = resolution.x > resolution.y ? resolution.x : resolution.y;
float scale = (6.0/pow(t,1.0 + t));
vec2 center = vec2(0.950005,-0.251205);
vec2 p = (gl_FragCoord.xy - resolution * 0.5) / res * scale;
vec2 z;
vec2 dc = p - center;
float radius = sqrt(p.x*p.x+p.y*p.y) / scale;
float rotation = PI + time * 0.5 - sin(time) * (6.0-t) * radius;
vec2 c = vec2(p.x*cos(rotation)-p.y*sin(rotation),p.x*sin(rotation)+p.y*cos(rotation)) - center;
float color = 0.0;
float max_iteration_float = exp(1.0 * sin(PI * 3.0/2.0) + t) * 20.0;
for (int iteration = 0;iteration < 1000;iteration++) {
z = product(z,z) + c;
color += 1.0;
if (color >= max_iteration_float) {
break;
}
if (z.x*z.x + z.y*z.y > 4.0) {
break;
}
}
p.xy = z;
color = (color / max_iteration_float);
float v = (0.5 * sin(radius * PI * sin(time * 0.2) * PI * 5.0)) + 0.5;
vec3 rgb = hsv2rgb(vec3(1.0 - color * 1.0,v, 1.0 - color * 1.0 ));
gl_FragColor=vec4(rgb,1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment