budhabrot

#define MAX_NUM 128

#define ITERATIONS 10000

//随机数设置,直接参考的IQ

vec2 rand( inout uint seed )

{

    seed = seed*0x343fdU + 0x269ec3U; uint x = seed;

    seed = seed*0x343fdU + 0x269ec3U; uint y = seed;

    return vec2( (uvec2(x,y)>>16)&32767U)/32767.0;

}

vec2 p2c( in vec2 p )

{

    vec2 q = p/iResolution.xy;

    q = -1.0 + 2.0*q;

    q.x *= iResolution.x/iResolution.y;

    return (q - vec2(0.5,0.0))*1.1;

}

float Mandelbrot(vec2 p)

{

    vec2 z= vec2(0.0,0.0);

    int i=0;

    for(;i

        z=vec2(z.x*z.x-z.y*z.y,2.*z.x*z.y)+p;

    if(i==MAX_NUM)

        return 0.0;

    else

        return 1.0;

}

float Budhabrot(vec2 p)

{

    float k=0.0;

    for(int i=0;i

    {

        if(Mandelbrot(p)<1.0);

        else k=k+1.0;

    }

    return k;

}

void mainImage( out vec4 fragColor, in vec2 fragCoord )

{

    //随机数设置,直接参考的IQ

    uvec2 p = uvec2(fragCoord-0.5);

    uint seed = uint(iFrame)*512U*8U + p.y*1920U+p.x;

    seed ^= (seed<<13);

vec2 c = vec2(0.0);

    for( int i=0; i<32; i++ )

    {

        vec2 of = rand(seed);

        c = p2c( of*iResolution.xy)*1.1;

        // test H1 and H2

        float c2 = dot(c,c);

        vec2  d = c + vec2(1.0,0.0);

        float h1 = 256.0*c2*c2 - 96.0*c2 + 32.0*c.x - 3.0;

        float h2 = 16.0*dot(d,d) - 1.0;

        if( h1>0.0 && h2>0.0 ) break;

    }

    float k=0.0;

    k=Budhabrot(c);

    vec3 col=pow(0.5,k)*0.3+vec3(0.1,0.1,0.1);

    // Output to screen

    fragColor = vec4(col,1.0);

}

你可能感兴趣的:(budhabrot)