fractorb
annotate mbrot.glsl @ 2:03e8b9a5031d
screenshot function
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 20 Nov 2017 03:53:02 +0200 |
parents | 6e849d7377ff |
children | f440ecffc45a |
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@1 | 6 uniform vec2 seed; |
nuclear@0 | 7 |
nuclear@0 | 8 float mbrot_dist_point(in vec2 c, in vec2 p) |
nuclear@0 | 9 { |
nuclear@0 | 10 vec2 z = c; |
nuclear@0 | 11 float mindist_sq = 8192.0; |
nuclear@0 | 12 |
nuclear@0 | 13 for(int i=0; i<ITER; i++) { |
nuclear@0 | 14 float x = (z.x * z.x - z.y * z.y) + c.x; |
nuclear@0 | 15 float y = (z.x * z.y + z.x * z.y) + c.y; |
nuclear@0 | 16 |
nuclear@0 | 17 z = vec2(x, y); |
nuclear@1 | 18 vec2 dir = z - seed; |
nuclear@1 | 19 mindist_sq = min(mindist_sq, dot(dir, dir)); |
nuclear@0 | 20 } |
nuclear@0 | 21 |
nuclear@0 | 22 return sqrt(mindist_sq); |
nuclear@0 | 23 } |
nuclear@0 | 24 |
nuclear@0 | 25 void main() |
nuclear@0 | 26 { |
nuclear@1 | 27 vec2 c = gl_TexCoord[0].xy; |
nuclear@0 | 28 float m = 1.0 - mbrot_dist_point(c, vec2(0.0, 0.0)); |
nuclear@0 | 29 |
nuclear@0 | 30 gl_FragColor.rgb = vec3(m, m, m); |
nuclear@0 | 31 gl_FragColor.a = 1.0; |
nuclear@0 | 32 } |