-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot.sttf
1 lines (1 loc) · 3.13 KB
/
mandelbrot.sttf
1
{"links":[{"end":"RenderOutput","filter":"Linear","slot":0,"start":"Image","wrapMode":"Repeat"}],"metadata":{"Author":"iq","Description":"Distance estimation to the Mandelbrot set. Basically, distance(c) = |G(c)|/|G'(c))|. More info in url=https://iquilezles.org/articles/distancefractals]this article[/url].","Name":"Mandelbrot - distance","ShaderToyURL":"https://www.shadertoy.com/view/lsX3W4"},"nodes":[{"class":"RenderOutput","name":"RenderOutput"},{"class":"GLSLShader","name":"Image","source":"// Copyright Inigo Quilez, 2013 - https://iquilezles.org/\n// I am the sole copyright owner of this Work.\n// You cannot host, display, distribute or share this Work neither\n// as it is or altered, here on Shadertoy or anywhere else, in any\n// form including physical and digital. You cannot use this Work in any\n// commercial or non-commercial product, website or project. You cannot\n// sell this Work and you cannot mint an NFTs of it or train a neural\n// network with it without permission. I share this Work for educational\n// purposes, and you can link to it, through an URL, proper attribution\n// and unmodified screenshot, as part of your educational material. If\n// these conditions are too restrictive please contact me and we'll\n// definitely work it out.\n\n// This shader computes the distance to the Mandelbrot Set for everypixel, and colorizes\n// it accoringly.\n// \n// Z -> Z²+c, Z0 = 0. \n// therefore Z' -> 2·Z·Z' + 1\n//\n// The Hubbard-Douady potential G(c) is G(c) = log Z/2^n\n// G'(c) = Z'/Z/2^n\n//\n// So the distance is |G(c)|/|G'(c)| = |Z|·log|Z|/|Z'|\n//\n// More info here: https://iquilezles.org/articles/distancefractals\n\n\nfloat distanceToMandelbrot( in vec2 c )\n{\n #if 1\n {\n float c2 = dot(c, c);\n // skip computation inside M1 - https://iquilezles.org/articles/mset1bulb\n if( 256.0*c2*c2 - 96.0*c2 + 32.0*c.x - 3.0 < 0.0 ) return 0.0;\n // skip computation inside M2 - https://iquilezles.org/articles/mset2bulb\n if( 16.0*(c2+2.0*c.x+1.0) - 1.0 < 0.0 ) return 0.0;\n }\n #endif\n\n // iterate\n float di = 1.0;\n vec2 z = vec2(0.0);\n float m2 = 0.0;\n vec2 dz = vec2(0.0);\n for( int i=0; i<300; i++ )\n {\n if( m2>1024.0 ) { di=0.0; break; }\n\n\t\t// Z' -> 2·Z·Z' + 1\n dz = 2.0*vec2(z.x*dz.x-z.y*dz.y, z.x*dz.y + z.y*dz.x) + vec2(1.0,0.0);\n\t\t\t\n // Z -> Z² + c\t\t\t\n z = vec2( z.x*z.x - z.y*z.y, 2.0*z.x*z.y ) + c;\n\t\t\t\n m2 = dot(z,z);\n }\n\n // distance\t\n\t// d(c) = |Z|·log|Z|/|Z'|\n\tfloat d = 0.5*sqrt(dot(z,z)/dot(dz,dz))*log(dot(z,z));\n if( di>0.5 ) d=0.0;\n\t\n return d;\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y;\n\n // animation\t\n\tfloat tz = 0.5 - 0.5*cos(0.225*iTime);\n float zoo = pow( 0.5, 13.0*tz );\n\tvec2 c = vec2(-0.05,.6805) + p*zoo;\n\n // distance to Mandelbrot\n float d = distanceToMandelbrot(c);\n \n // do some soft coloring based on distance\n\td = clamp( pow(4.0*d/zoo,0.2), 0.0, 1.0 );\n \n vec3 col = vec3(d);\n \n fragColor = vec4( col, 1.0 );\n}\n","type":"Image"}]}