blob: 65679fcc6712eed82e41d3648df9a09ef4b275e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#version 100
precision highp float;
uniform vec2 resolution;
uniform vec2 location;
uniform float zoom;
uniform int max;
vec2 compsquare(vec2 z) {
float temp = z.x;
z.x = z.x * z.x - z.y * z.y;
z.y = 2.0 * temp * z.y;
return z;
}
vec3 hsv2rgb(vec3 hue){
vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
vec3 p = abs(fract(hue.xxx + K.xyz) * 6.0 - K.www);
return hue.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), hue.y);
}
vec3 mandelbort(vec2 point){
vec2 z = vec2(0.0);
float iters = 0.0;
for (iters = 0.0; iters < float(max); ++iters)
{
z = compsquare(z) + point;
if(dot(z, z) > 4.0) break;
}
float hue = iters / float(max);
if(hue > 0.98) return vec3(0.0);
return hsv2rgb(vec3(hue, 1.0, 1.0));
}
void main()
{
vec2 uv = gl_FragCoord.xy / resolution;
uv.x *= resolution.x / resolution.y;
uv -= vec2(0.7, 0.5);
uv *= zoom;
uv -= location;
gl_FragColor = vec4(mandelbort(uv), 1.0);
}
|