fractorb
diff mbrot.glsl @ 0:6e849d7377ff
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 18 Nov 2017 20:04:16 +0200 |
parents | |
children | 436f82447c44 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mbrot.glsl Sat Nov 18 20:04:16 2017 +0200 1.3 @@ -0,0 +1,30 @@ 1.4 +// vi:ft=glsl: 1.5 +#define ITER 96 1.6 + 1.7 +uniform float view_scale; 1.8 +uniform vec2 view_center; 1.9 + 1.10 +float mbrot_dist_point(in vec2 c, in vec2 p) 1.11 +{ 1.12 + vec2 z = c; 1.13 + float mindist_sq = 8192.0; 1.14 + 1.15 + for(int i=0; i<ITER; i++) { 1.16 + float x = (z.x * z.x - z.y * z.y) + c.x; 1.17 + float y = (z.x * z.y + z.x * z.y) + c.y; 1.18 + 1.19 + z = vec2(x, y); 1.20 + mindist_sq = min(mindist_sq, dot(z, z)); 1.21 + } 1.22 + 1.23 + return sqrt(mindist_sq); 1.24 +} 1.25 + 1.26 +void main() 1.27 +{ 1.28 + vec2 c = gl_TexCoord[0].xy * view_scale - view_center; 1.29 + float m = 1.0 - mbrot_dist_point(c, vec2(0.0, 0.0)); 1.30 + 1.31 + gl_FragColor.rgb = vec3(m, m, m); 1.32 + gl_FragColor.a = 1.0; 1.33 +}