daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef GL_FRAGMENT_PRECISION_HIGH
  2. precision highp float;
  3. #else
  4. precision mediump float;
  5. #endif
  6.  
  7. #define AA 1
  8.  
  9. #define PI (acos(-1.0))
  10. #define MAXI 75.0
  11.  
  12. #define PATHTIME 24.
  13.  
  14. #define wobbleSize 1.
  15. #define wobbleSpeed 10.
  16.  
  17. #define isJulia true
  18. #define gridOn false
  19.  
  20. uniform vec2 resolution;
  21. uniform vec3 pointers[10];
  22. uniform int pointerCount;
  23. uniform float startRandom;
  24. uniform sampler2D backbuffer;
  25. uniform vec4 date;
  26. uniform float time;
  27.  
  28. //elliptical path around julia seed, /w zoom & offset
  29. struct path {
  30.   vec2 center;
  31.   float radius;
  32.   float elliptivity;
  33.   float rotations;
  34.   vec2 offsetStart;
  35.   vec2 offsetEnd;
  36.   float zoomStart;
  37.   float zoomEnd;
  38. };
  39.  
  40. #define NUMPATHS 22
  41. //update NUMPATHS if you change the number of paths here
  42. //replace data-structure above with a function?
  43. path get_path(int p) {
  44.     //Format:
  45.     //path(vec2(julia seed center), radius, elliptivity, rotations, vec2(offstart), vec2(offset), zoomStart, zoomEnd)
  46.     //Data:
  47.     //path(vec2(.0  , .0  ), .0 , 1., 1., vec2(.0 , .0)  , vec2(.0, .0), 1.  , 1.), //
  48.     //p = 21;
  49.     if (p < 9){ //0-8
  50.       if (p < 5) { //0-4
  51.         if (p < 3) { //0-2
  52.           if (p == 0) return path(vec2(.35  , .36  ), .01 , 1., 1., vec2(-.2 , .5895)  , vec2(-.2, .5895), 4.  , 7.);
  53.           if (p == 1) return path(vec2(-.16  , 1.03  ), .01 , 1., 1., vec2(-.35 , .51)  , vec2(-.35, .51), 350.  , 10.);
  54.           if (p == 2) return path(vec2(-.12  , .74  ), .08 , 1., 3., vec2(-.3 , .85)  , vec2(-.25, .85), 100.  , 4.);
  55.         } else { //3-4
  56.           if (p == 3) return path(vec2(-1.33  , .05  ), .02 , 3., 1., vec2(.1 , .15)  , vec2(.1, .1), 200.  , 5.);
  57.           if (p == 4) return path(vec2(-.755  , .01  ), .085 , .3, 5., vec2(-.6 , .2)  , vec2(.0, .85), 5.  , 25.);
  58.         }
  59.       } else { //5-8
  60.         if (p < 7) { //5-6
  61.           if (p == 5) return path(vec2(-1.12  , .26  ), .01, 1., 4., vec2(-1.14, .19)  , vec2(-1.14, .19), 2.  , 60.);
  62.           if (p == 6) return path(vec2(-1.2  , .18  ), .04 , 1., 3., vec2(-.8 , .04)  , vec2(.0, .0), 10.  , 1.);
  63.         } else { //7-8
  64.           if (p == 7) return path(vec2(-.16   , 1.035  ), .04 , 1., 1., vec2(1.0 , -1.0)  , vec2(.0, .0), 1.  , 10.);
  65.           if (p == 8) return path(vec2(-.12 , .005 ), .68 , 1., .3, vec2(-.5 , .5)  , vec2(.0, .0), 5., 2.);
  66.         }
  67.       }
  68.     } else { //9-17
  69.       if (p < 14) { //9-13
  70.         if (p < 12) { //9-11
  71.           if (p == 9) return path(vec2(-1.  , .005 ), .32 , 1., 1., vec2(-.1 , .1)  , vec2(.1, -.1), 1.  , 1.3);
  72.           if (p == 10) return path(vec2(-1.32, .0025), .065, 1., 1.5, vec2(-1.4 , .0)  , vec2(1.0, .0), 3.  , 4.);
  73.           if (p == 11) return path(vec2(-1.77, .0075), .02 , 1., 1., vec2(-1.0 , .0)  , vec2(.0, .0), 1.5  , 11.5);
  74.         } else { //12-13
  75.           if (p == 12) return path(vec2(-.13 , .77  ), .12 , 1., 2., vec2(.0 , .0)  , vec2(0.0, .0),  1.  , 1.);
  76.           if (p == 13) return path(vec2(-1.  , .005 ), .32 , 1., 1.7, vec2(.0 , .0)  , vec2(.0, .0), 1.  , 1.);
  77.         }
  78.       } else { //14-17
  79.         if (p < 16) { //14-15
  80.           if (p == 14) return path(vec2(-1.  , .25 ), .01 , 1., 5., vec2(1.0 , .33)  , vec2(1., .0), 25.  , 3.);
  81.           if (p == 15) return path(vec2(.32  , -.01 ), .03 , .2, 2., vec2(.4 , .9)  , vec2(.6, .2), 15.  , 1.);
  82.         } else { //16-17
  83.           if (p == 16) return path(vec2(.42  , .20  ), .03 , 1., 1.5, vec2(.23 , .48)  , vec2(.23, .48), 1.  , 15.);
  84.           if (p == 17) return path(vec2(-1.48, .015 ), .1, .2, 3., vec2(-1.,  -.1)  , vec2(.8, .0), 3., 8.);
  85.           if (p == 18) return path(vec2(-1.10, .3 ), .015, 2., 1., vec2(-.02,  .46)  , vec2(-.02,.46), 4., 400.);
  86.             if (p == 19) return path(vec2(-.9, .3 ), .3, .2, 1., vec2(-.5,  .1)  , vec2(-.5, .1), 30., 3.);
  87.             if (p == 20) return path(vec2(.35, .15 ), .15, .2, 1., vec2(.0,  .3)  , vec2(.5, .5), 1., 3.);
  88.             if (p == 21) return path(vec2(.45, .25 ), .1, .4, 1., vec2(.0,  .5)  , vec2(.0, .5), 1., 3.);
  89.         }
  90.       }
  91.    }
  92. }
  93.  
  94.  
  95.  
  96. float interval(float e1, float e2, float x) {
  97.     if (x >= e1 && x <= e2) return 1.;
  98.     return 0.;
  99. }
  100.  
  101.  
  102.  
  103. //dim for a small time as paths change
  104. float get_dimming_factor(float t) {
  105.   if (t < .05)
  106.     return smoothstep(.0, .05, t);
  107.   if (t > .95)
  108.     return 1.-smoothstep(.95, 1., t);
  109.  
  110.   return 1.;
  111. }
  112.  
  113.  
  114.  
  115. vec2 mandel(vec2 uv0, vec2 c) {
  116.     vec2 uv = vec2(0, 0);
  117.     if (isJulia) {
  118.         uv = uv0;
  119.         //uv0 = vec2(0.0);
  120.     }
  121.     float xtemp, logzn, nu;
  122.     float i = 0.0;
  123.  
  124.   if (!isJulia) {
  125.     while (length(uv) < 64.0 && i < MAXI) {
  126.       xtemp = uv.x*uv.x - uv.y*uv.y + uv0.x;
  127.             uv.y = 2.0*uv.x*uv.y + uv0.y;
  128.             uv.x = xtemp;
  129.             i++;
  130.     }
  131.   } else {
  132.     while (length(uv) < 64.0 && i < MAXI) {
  133.       xtemp = uv.x*uv.x - uv.y*uv.y + c.x;
  134.             uv.y = 2.0*uv.x*uv.y + c.y;
  135.             uv.x = xtemp;
  136.             i++;
  137.     }
  138.   }
  139.  
  140.     if (i < MAXI) {
  141.         logzn = log(length(uv)) / 2.0;
  142.         nu = log(logzn / log(2.0)) / log(2.0);
  143.         i = i + 1.0 - nu;
  144.     }
  145.  
  146.     //pixels in the set could be transparent/black
  147.     if (i/MAXI > .9) i *= 1.-smoothstep(.9, 1., i/MAXI);
  148.  
  149.     return vec2(i, i);
  150. }
  151.  
  152.  
  153.  
  154. vec4 mandel2(vec2 z, vec2 c) {
  155.     float i;
  156.     vec2 dz = z;
  157.  
  158.     float trap1 = 0.;
  159.     float trap2 = 1e20;
  160.     float co2 = 0.;
  161.     vec2 t2c = vec2(-.5, 2.);
  162.     t2c += .5*vec2(cos(time*.2), sin(time*.2));
  163.  
  164.     for (i = 0.; i < MAXI; i++) {
  165.         if (dot(z,z) > 1024. ) break;
  166.  
  167.         dz = 2.*vec2(z.x*dz.x - z.y*dz.y, z.x*dz.y + z.y*dz.x) + vec2(1., 1.);
  168.         z = c + vec2(z.x*z.x - z.y*z.y, 2.*z.x*z.y);
  169.  
  170.         //trap1
  171.         float d1 = abs(dot(z-vec2(0.,0.), vec2(2.707)));
  172.         float ff = step(d1, 1.);
  173.         co2 += ff;
  174.         trap1 += ff*d1;
  175.  
  176.         //trap2
  177.         trap2 = min(min(trap2, dot(z-t2c, z-t2c)),dot(z*z, z*z));
  178.     }
  179.  
  180.     float d = sqrt(dot(z,z)/dot(dz,dz))*log(dot(z,z));
  181.  
  182.     //float c1 = pow(clamp(2.*d, 0., .1), .5);
  183.     float c2 = pow(clamp(1.5*trap1/co2, 0., .1), 2.);
  184.     float c3 = pow(clamp(.4*trap2, 0., .1), .25);
  185.  
  186.     if (i < MAXI) {
  187.         float logzn = log(length(z)) / 2.0;
  188.         float nu = log(logzn / log(2.0)) / log(2.0);
  189.         i = i + 1.0 - nu;
  190.     }
  191.  
  192.     if (i/MAXI > .9) i *= 1.-smoothstep(.9, 1., i/MAXI);
  193.  
  194.     return vec4(i, d, c2, c3);
  195. }
  196.  
  197.  
  198.  
  199. #define numColourModes 13.
  200. //mandel, time, dist
  201. vec4 palette(float m, float md, float t1, float t2,
  202.     float t, float d, int colourMode) {
  203.   //transparent inside set and far outside
  204.     if (m == 0.0 || m < 1.0) return vec4(0.0);
  205.  
  206.     float ms = m/float(MAXI);
  207.  
  208.     vec3 r = vec3(1., 0., 0.);
  209.     vec3 g = vec3(0., 1., 0.);
  210.     vec3 b = vec3(0., 0., 1.);
  211.  
  212.     vec3 spread = vec3(1., 2., 3.);
  213.  
  214.   vec3 col = vec3(0.);
  215.  
  216.   //colourMode = 12;
  217.  
  218.   if (colourMode == 0) {
  219.     //mode 0
  220.     float c = 111.9 * d + -9.*t + 1.*m;
  221.  
  222.     r *= smoothstep(0.3, .6-0.3*sin(c), ms);
  223.     g *= smoothstep(0.1, .6-0.3*sin(c), ms);
  224.     b *= smoothstep(0.4, .6-0.3*sin(c), ms);
  225.  
  226.     col = ms * sqrt(r+g+b);
  227.   } else if (colourMode == 1) {
  228.     //mode 1
  229.     float c = 10.9 * d + -9.*t + 3.*m;
  230.  
  231.     r *= smoothstep(0.1, 1.-0.5*sin(c), ms);
  232.     g *= smoothstep(0.3, 1.-0.5*sin(c), ms);
  233.     b *= smoothstep(0.5, 1.-0.5*sin(c), ms);
  234.  
  235.     col = r+g+b;
  236.   } else if (colourMode == 2) {
  237.     //mode 2
  238.     float c = m * (0.45);
  239.     c -= 6. * t;
  240.     c += 10. * d;
  241.  
  242.     r *= sin(c);
  243.     g *= sin(c+1.);
  244.     b *= sin(c+2.);
  245.  
  246.     col = sqrt(ms)*vec3(r + g + b);
  247.   } else if (colourMode == 3) {
  248.     //mode 3
  249.     float c = m * (0.25);
  250.     c -= 6. * t;
  251.     c += 6.0 * d;
  252.  
  253.     r *= sin(c+1.);
  254.     g *= sin(c+2.);
  255.     b *= sin(c);
  256.  
  257.     col = ms*vec3(r + g + b);
  258.   } else if (colourMode == 4) {
  259.     //mode 4
  260.     col = 1.*smoothstep(0., .9, sin(1.5*ms*spread))+
  261.         smoothstep(.98, .99, sin(100.*ms+2.*t));
  262.   } else if (colourMode == 5) {
  263.     //mode 5
  264.     float c = 2.*t + 1.*m;
  265.  
  266.     r *= smoothstep(0.0, 1.-0.7*cos(t+1.), ms);
  267.     g *= smoothstep(0.05, 1.-0.7*sin(t+2.)*cos(1.7*t), ms);
  268.     b *= smoothstep(0.15, 1.-0.7*sin(t)*sin(1.7*t), ms);
  269.  
  270.     col = ms*((r+g+b)+
  271.         smoothstep(.9, 1., abs(sin(300.*md)))*
  272.         sin(vec3(10.*d, 5.*d, 3.*d)));
  273.   } else if (colourMode == 6) {
  274.     //mode 6
  275.     vec3 o = vec3(1.,2.,3.);
  276.     col = ms*sin(4.*ms + .5*t*o + 1.5*d);
  277.   } else if (colourMode == 7) {
  278.     //mode 7
  279.     float c = m * (0.45);
  280.         c -= 2.0 * t;
  281.         c += 3.0 * d;
  282.  
  283.         col = ms*sin(ms*vec3(2.,3.,4.))*
  284.             (.1+.9*smoothstep(.0, .1, ms));
  285.   } else if (colourMode == 8) {
  286.     //mode 8
  287.     float c = 8.*t + 3.*m;
  288.  
  289.     r *= smoothstep(0.1, 1.-0.5*cos(t), ms);
  290.     g *= smoothstep(0.3, 1.-0.5*sin(t)*cos(1.7*t), ms);
  291.     b *= smoothstep(0.5, 1.-0.5*sin(t)*sin(1.7*t), ms);
  292.  
  293.     col = ms*((r+g+b)+
  294.         .2*smoothstep(.97, 1., abs(sin(c))));
  295.   }else if (colourMode == 9) {
  296.     //mode 9
  297.     float c = 20.8*pow(m/(.1+md), .1);
  298.  
  299.     float p1 = interval(.02, .2, fract(c))*
  300.         1.;
  301.     float p2 = interval(.22, 1., fract(c))*
  302.         1.;
  303.  
  304.     r *= abs(sin(28.*c+1.));
  305.     g *= abs(sin(28.*c-1.));
  306.     b *= abs(sin(28.*c));
  307.  
  308.     vec3 c2 = vec3(
  309.         smoothstep(.2,.5,ms),
  310.         smoothstep(.0,.2,ms),
  311.         smoothstep(.0,.1,ms));
  312.  
  313.     c2 = c2*vec3(.9,.8,1.);
  314.  
  315.     vec3 w = vec3(.9,.9,.99)*(
  316.         interval(.2, .22, fract(c))+
  317.         interval(.0, .02, fract(c)));
  318.  
  319.     col = w +
  320.         (r+g+b)*p1 + p2*c2;
  321.   } else if (colourMode == 10) {
  322.     //mode 4
  323.     col = 1.*smoothstep(0., .9, sin(10.*ms*spread))+
  324.         smoothstep(.98, .99, sin(100.*ms+t));
  325.   } else if (colourMode == 11) {
  326.     //mode 4
  327.     float c1 = pow(clamp(.1*md, 0., .1), .5);
  328.     vec3 col1 = .8 + 5.*sin(3.+5.*t1+vec3(.0,.5,1.));
  329.     vec3 col2 = .8 + 5.*sin(4.+2.*(2.+sin(t*.2))*t2+vec3(1.,.1,.0));
  330.     col = .8*sqrt(c1*col1*col2);
  331.   }else if (colourMode == 12) {
  332.     //mode 4
  333.     float c1 = pow(clamp(2.*md, 0., .1), .5);
  334.     vec3 col1 = .5 + 5.*sin(3.+4.*t1+vec3(.0,.5,1.));
  335.     vec3 col2 = .5 + 5.*sin(4.+2.*t2+vec3(1.,.5,.0));
  336.     col = 1.8*sqrt(c1*col1*col2);
  337.   }
  338.  
  339.     return vec4(col, ms);
  340. }
  341.  
  342.  
  343.  
  344. vec2 path_position(path cPath, float t, float zoom) {
  345.   vec2 elliptivity = vec2(min(cPath.elliptivity, 1.), min(1./cPath.elliptivity, 1.));
  346.  
  347.   //half circle paths
  348.   return cPath.center +
  349.     cPath.radius * elliptivity *
  350.     vec2(cos(t*cPath.rotations*2.*PI),
  351.         sin(t*cPath.rotations*2.*PI)) +
  352.     cPath.radius * (wobbleSize/zoom) *
  353.     vec2(cos(t*wobbleSpeed),
  354.         sin(t*wobbleSpeed));
  355. }
  356.  
  357.  
  358.  
  359. void main(void)
  360. {
  361.     //date = year, month, day, second
  362.     //time is seconds since load
  363.     //rtime controls the animation, so it's
  364.     //starting point advances slowly over time
  365.   float rtime = 24.*60.*date.z + //days (in mins)
  366.     60.*floor(date.w/3600.) + //hours (in mins)
  367.     mod(date.w,3600.)/60. + //mins+secs (in mins)
  368.     time; //1 sec since load = 1 min
  369.  
  370.   vec4 col = vec4(0.);
  371.  
  372.   vec2 uvTex = gl_FragCoord.xy / resolution.xy;
  373.  
  374.   vec2 uv0 = gl_FragCoord.xy / resolution.xy;
  375.  
  376.   //adjust positions to fit mandelbrot:
  377.   //x=[-1.2, 1.2]; y=[-2.5, 1.0]
  378.   uv0.y = -1.2 + 2.4 * uv0.y;
  379.   uv0.x = -3.0 + 4.0 * uv0.x;
  380.  
  381.   //adjust positions to julia space
  382.   if (isJulia) {
  383.     uv0 += vec2(1., 0.);
  384.   }
  385.  
  386.   //calculate mandelbrot / julias
  387.   //mandel/julia value, distance est.
  388.   vec4 mandel;
  389.   //path position along mandel
  390.   vec2 pathPos;
  391.  
  392.   //int currentPath = int(mod(rtime/PATHTIME, float(NUMPATHS)));
  393.   int currentPath = int(
  394.     mod(floor(rtime/PATHTIME)*1.38345611,
  395.         float(NUMPATHS)));
  396.   float pathTime = mod(rtime, PATHTIME) / PATHTIME;
  397.   path cPath = get_path(currentPath);
  398.  
  399.   float dimmingFactor = get_dimming_factor(pathTime);
  400.  
  401.  
  402.   //zoom and offset using smooth motion
  403.   float pathZoom =
  404.     cPath.zoomStart * smoothstep(1., 0., pathTime) +
  405.         cPath.zoomEnd * smoothstep(0., 1., pathTime);
  406.   vec2 pathOffset =
  407.     cPath.offsetStart * smoothstep(1., 0., pathTime) +
  408.         cPath.offsetEnd * smoothstep(0., 1., pathTime);
  409.   if (!isJulia) {
  410.     pathZoom = 1.;
  411.     pathOffset = vec2(0.);
  412.   }
  413.  
  414.   int colourMode = int(
  415.           mod(floor(rtime/PATHTIME)*1.379431,
  416.             numColourModes));
  417.  
  418.     float d;
  419.   for( int m=0; m<AA; m++ )
  420.       for( int n=0; n<AA; n++ ) {
  421.         vec2 uv = (1./pathZoom)*(uv0 + vec2(vec2(float(m), float(n))/float(AA)) / resolution.xy) + pathOffset;
  422.  
  423.         //distance
  424.         d = 0.;
  425.  
  426.         pathPos = path_position(cPath,
  427.             pathTime, pathZoom);
  428.  
  429.         //if (!isJulia) {
  430.         //  mandel = mandel(uv, pathPos) + mandel(uv, pathPos);
  431.         //} else {
  432.           mandel = mandel2(uv, pathPos);
  433.         //}
  434.  
  435.                 //distance from slowly rotating offset
  436.         d = pathZoom*length(uv-(pathOffset+
  437.           3.*vec2(sin(rtime*.01),cos(rtime*.01))
  438.           /pathZoom));
  439.  
  440.         col += (1./float(AA*AA))*
  441.           palette(mandel.x, mandel.y, mandel.z,
  442.             mandel.w, rtime, d, colourMode)*
  443.             dimmingFactor;
  444.       }
  445.  
  446.     vec4 bb = texture2D(backbuffer, 1.*uvTex+vec2(-.05));
  447.  
  448.     float bbOn = .8*smoothstep(.05, .1, uvTex.x*uvTex.y);
  449.     //if (colourMode != 9) bbOn = 0.;
  450.     vec4 ncol = (col + bbOn*bb);
  451.  
  452.  
  453.     vec3 spread = vec3(0., 2., 4.);
  454.     /*float pSize = .01+.3*abs(sin(rtime));
  455.     float pModx = pSize-2.*abs(mod(uv0.x, pSize)-.5*pSize);
  456.     pModx /= pSize;
  457.     float pMody = pSize-2.*abs(mod(uv0.y, pSize)-.5*pSize);
  458.     pMody /= pSize;
  459.     col *= 1./(1.+5.*pModx) + 1./(1.+5.*pMody);
  460.     */
  461.     /*float aStreak = 5.*d + 2.*time;
  462.     if (mod(aStreak, 3.*2.*PI) < 1.1*PI)
  463.         col.rgb *= 1.-sin(aStreak+spread);
  464.     */
  465.  
  466.     gl_FragColor = col;
  467. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top