fractorb

annotate 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
rev   line source
nuclear@0 1 // vi:ft=glsl:
nuclear@0 2 #define ITER 96
nuclear@0 3
nuclear@0 4 uniform float view_scale;
nuclear@0 5 uniform vec2 view_center;
nuclear@0 6
nuclear@0 7 float mbrot_dist_point(in vec2 c, in vec2 p)
nuclear@0 8 {
nuclear@0 9 vec2 z = c;
nuclear@0 10 float mindist_sq = 8192.0;
nuclear@0 11
nuclear@0 12 for(int i=0; i<ITER; i++) {
nuclear@0 13 float x = (z.x * z.x - z.y * z.y) + c.x;
nuclear@0 14 float y = (z.x * z.y + z.x * z.y) + c.y;
nuclear@0 15
nuclear@0 16 z = vec2(x, y);
nuclear@0 17 mindist_sq = min(mindist_sq, dot(z, z));
nuclear@0 18 }
nuclear@0 19
nuclear@0 20 return sqrt(mindist_sq);
nuclear@0 21 }
nuclear@0 22
nuclear@0 23 void main()
nuclear@0 24 {
nuclear@0 25 vec2 c = gl_TexCoord[0].xy * view_scale - view_center;
nuclear@0 26 float m = 1.0 - mbrot_dist_point(c, vec2(0.0, 0.0));
nuclear@0 27
nuclear@0 28 gl_FragColor.rgb = vec3(m, m, m);
nuclear@0 29 gl_FragColor.a = 1.0;
nuclear@0 30 }