//https://www.shadertoy.com/view/wt33Dn
mat2 rot(float a){float c=cos(a),s=sin(a);return mat2(c,-s,s,c);}
//----------
float Value2D(vec2 P)
{
    //  https://github.com/BrianSharpe/Wombat/blob/master/Value2D.glsl
    
    //	establish our grid cell and unit position
    vec2 Pi=floor(P);
    vec2 Pf=P-Pi;
    
    //	calculate the hash.
    vec4 Pt=vec4(Pi.xy,Pi.xy+1.);
    Pt=Pt-floor(Pt*(1./71.))*71.;
    Pt+=vec2(26.,161.).xyxy;
    Pt*=Pt;
    Pt=Pt.xzxz*Pt.yyww;
    vec4 hash=fract(Pt*(1./951.135664));
    
    //	blend the results and return
    vec2 blend=Pf*Pf*Pf*(Pf*(Pf*6.-15.)+10.);
    vec4 blend2=vec4(blend,vec2(1.-blend));
    return dot(hash,blend2.zxzx*blend2.wwyy);
}
float SimplexPerlin2D(vec2 P)
{
    //  https://github.com/BrianSharpe/Wombat/blob/master/SimplexPerlin2D.glsl
    
    //  simplex math constants
    const float SKEWFACTOR=.36602540378443864676372317075294;// 0.5*(sqrt(3.0)-1.0)
    const float UNSKEWFACTOR=.21132486540518711774542560974902;// (3.0-sqrt(3.0))/6.0
    const float SIMPLEX_TRI_HEIGHT=.70710678118654752440084436210485;// sqrt( 0.5 )	height of simplex triangle
    const vec3 SIMPLEX_POINTS=vec3(1.-UNSKEWFACTOR,-UNSKEWFACTOR,1.-2.*UNSKEWFACTOR);//  simplex triangle geo
    
    //  establish our grid cell.
    P*=SIMPLEX_TRI_HEIGHT;// scale space so we can have an approx feature size of 1.0
    vec2 Pi=floor(P+dot(P,vec2(SKEWFACTOR)));
    
    // calculate the hash
    vec4 Pt=vec4(Pi.xy,Pi.xy+1.);
    Pt=Pt-floor(Pt*(1./71.))*71.;
    Pt+=vec2(26.,161.).xyxy;
    Pt*=Pt;
    Pt=Pt.xzxz*Pt.yyww;
    vec4 hash_x=fract(Pt*(1./951.135664));
    vec4 hash_y=fract(Pt*(1./642.949883));
    
    //  establish vectors to the 3 corners of our simplex triangle
    vec2 v0=Pi-dot(Pi,vec2(UNSKEWFACTOR))-P;
    vec4 v1pos_v1hash=(v0.x<v0.y)?vec4(SIMPLEX_POINTS.xy,hash_x.y,hash_y.y):vec4(SIMPLEX_POINTS.yx,hash_x.z,hash_y.z);
    vec4 v12=vec4(v1pos_v1hash.xy,SIMPLEX_POINTS.zz)+v0.xyxy;
    
    //  calculate the dotproduct of our 3 corner vectors with 3 random normalized vectors
    vec3 grad_x=vec3(hash_x.x,v1pos_v1hash.z,hash_x.w)-.49999;
    vec3 grad_y=vec3(hash_y.x,v1pos_v1hash.w,hash_y.w)-.49999;
    vec3 grad_results=inversesqrt(grad_x*grad_x+grad_y*grad_y)*(grad_x*vec3(v0.x,v12.xz)+grad_y*vec3(v0.y,v12.yw));
    
    //	Normalization factor to scale the final result to a strict 1.0->-1.0 range
    //	http://briansharpe.wordpress.com/2012/01/13/simplex-noise/#comment-36
    const float FINAL_NORMALIZATION=99.204334582718712976990005025589;
    
    //	evaluate and return
    vec3 m=vec3(v0.x,v12.xz)*vec3(v0.x,v12.xz)+vec3(v0.y,v12.yw)*vec3(v0.y,v12.yw);
    m=max(.5-m,0.);
    m=m*m;
    return dot(m*m,grad_results)*FINAL_NORMALIZATION;
}

//----------
mat2 rotate (float t) {
    return mat2(cos(t), sin(t), -sin(t), cos(t));
}

float fBm(vec2 st, float noisetype) {

    float frequency = 1.0;
    float amplitude = 0.5;
    float value = 0.0;

    for (float i = 0.; i <6.+7.*sin(iTime*.5)*sin(iTime*.95)+1.; i++) {
        if (noisetype == 0.0)
            value += amplitude * Value2D(frequency * st);
        else
            value += amplitude * SimplexPerlin2D(frequency * st);
        frequency *= 2.0;
        amplitude *= 0.5;
        st = rotate(0.4) * st;

    }

    return value;
}

float warp (vec2 st, float noise) {
    // f(p) = f(p + h(p))
    // h(p): vec2->vec2
    float r = 0.0;
    r = fBm(st, noise);
    vec2 st1 = vec2(0.0);

    st1.x = fBm(st, noise);
    st1.y = fBm(st + vec2(1.0), noise);

    st1.x = fBm(st + st1 + 0.15 * iTime, noise);
    st1.y = fBm(st + st1 + 0.125 * iTime + vec2(100.0, 12323.0), noise);
    return fBm(st + st1, noise);

}

void mainImage(out vec4 fragColor,in vec2 fragCoord)
{vec2 st=gl_FragCoord.xy/iResolution.xy;
    float yf = fract(st.y * 3.0);
    float xf = st.x;

    float scale = 5.0;
    st *= scale;
    float r = 0.0;

    if (st.x < 0.5 * scale) {

        
            r = warp(st, 0.0);
            vec3 co=vec3(r);
            fragColor=vec4(co,1.);
      

    } else {
        
            r = warp(st, 1.0);
            float t=iTime*.13;
vec3 eye=vec3(st,-2.5);
vec3 pos=eye;
vec3 norm=normalize(pos);//  
norm.xy*=rot(t+pos.z);//  §ã§Ú§ß§Ö-§Ü§â§Ñ§ã§ß§í§Û
norm.xz*=rot(t+pos.y);//  §Ù§Ö§Ý§×§ß§à-§æ§Ú§à§Ý§Ö§ä§à§Ó§í§Û
norm.yz*=rot(t+pos.x);//  §Ø§Ö§Ý§ä§à-§ã§Ú§ß§Ú§Û
vec4 col=vec4(norm,0.);
fragColor=col;
        
    }
    
    r*=smoothstep(0.,.005,abs(xf-.5));
    
    vec3 color = vec3(r);
    fragColor*= vec4(color , 1.0);

}
