Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. #ifdef GL_ES
  2. precision highp float; // ios
  3. #endif
  4.  
  5.  
  6. uniform float time;
  7. uniform vec2 resolution;
  8.  
  9.  
  10. #define iterations 4
  11. #define formuparam2 .9
  12.  
  13. #define volsteps 5
  14. #define stepsize 0.190
  15.  
  16. #define zoom 2.9
  17. #define tile 0.45
  18. #define speed2 0.0
  19.  
  20. #define brightness 0.1
  21. #define darkmatter 0.4
  22. #define distfading 0.56
  23. #define saturation 0.9
  24.  
  25.  
  26. #define transverseSpeed 0.0
  27. #define cloud 0.2
  28.  
  29.  
  30. float triangle(float x, float a)
  31. {
  32. float output2 = 2.0*abs( 2.0* ( (x/a) - floor( (x/a) + 0.5) ) ) - 1.0;
  33. return output2;
  34. }
  35.  
  36.  
  37. float field(in vec3 p) {
  38. float strength = 8. + .03 * log(1.e-6 + fract(sin(time) * 4373.11));
  39. float accum = 0.;
  40. float prev = 0.;
  41. float tw = 0.;
  42.  
  43.  
  44. for (int i = 0; i < 6; ++i) {
  45. float mag = dot(p, p);
  46. p = abs(p) / mag + vec3(-.5, -.8 + 0.1*sin(time*0.2 + 2.0), -1.1+0.3*cos(time*0.15));
  47. float w = exp(-float(i) / 7.);
  48. accum += w * exp(-strength * pow(abs(mag - prev), 2.3));
  49. tw += w;
  50. prev = mag;
  51. }
  52. return max(0., 5. * accum / tw - .7);
  53. }
  54.  
  55.  
  56.  
  57. void main()
  58. {
  59. vec2 uv2 = 2. * gl_FragCoord.xy / resolution.xy - 1.;
  60. vec2 uvs = uv2 * resolution.xy / max(resolution.x, resolution.y);
  61.  
  62.  
  63. float time2 = time*0.7;
  64.  
  65. float speed = speed2;
  66. //speed = 0.005 * cos(time2*0.002 + 3.1415926/4.0);
  67.  
  68. speed = 0.1;
  69.  
  70.  
  71. float formuparam = formuparam2;
  72.  
  73.  
  74.  
  75. //get coords and direction
  76.  
  77. vec2 uv = uvs;
  78.  
  79.  
  80.  
  81. //mouse rotation
  82. float a_xz = 0.9;
  83. float a_yz = -.6;
  84. float a_xy = 0.9 + time*0.04;
  85.  
  86.  
  87. mat2 rot_xz = mat2(cos(a_xz),sin(a_xz),-sin(a_xz),cos(a_xz));
  88.  
  89. mat2 rot_yz = mat2(cos(a_yz),sin(a_yz),-sin(a_yz),cos(a_yz));
  90.  
  91. mat2 rot_xy = mat2(cos(a_xy),sin(a_xy),-sin(a_xy),cos(a_xy));
  92.  
  93.  
  94. float v2 =1.0;
  95.  
  96. vec3 dir=vec3(uv*zoom,1.);
  97.  
  98. vec3 from=vec3(0.0, 0.0,0.0);
  99.  
  100.  
  101. vec3 forward = vec3(0.,0.,1.);
  102.  
  103.  
  104. from.x += transverseSpeed*(1.0)*cos(0.01*time) + 0.001*time;
  105. from.y += transverseSpeed*(1.0)*sin(0.01*time) +0.001*time;
  106.  
  107. from.z += 0.003*time;
  108.  
  109.  
  110. dir.xy*=rot_xy;
  111. forward.xy *= rot_xy;
  112.  
  113. dir.xz*=rot_xz;
  114. forward.xz *= rot_xz;
  115.  
  116.  
  117. dir.yz*= rot_yz;
  118. forward.yz *= rot_yz;
  119.  
  120.  
  121.  
  122. from.xy*=-rot_xy;
  123. from.xz*=rot_xz;
  124. from.yz*= rot_yz;
  125.  
  126.  
  127. //zoom
  128. float zooom = (time2-3311.)*speed;
  129. from += forward* zooom;
  130. float sampleShift = mod( zooom, stepsize );
  131.  
  132. float zoffset = -sampleShift;
  133. sampleShift /= stepsize; // make from 0 to 1
  134.  
  135.  
  136.  
  137. //volumetric rendering
  138. float s=0.24;
  139. float s3 = s + stepsize/2.0;
  140. vec3 v=vec3(0.);
  141. float t3 = 0.0;
  142.  
  143.  
  144. vec3 backCol2 = vec3(0.);
  145. for (int r=0; r<volsteps; r++) {
  146. vec3 p2=from+(s+zoffset)*dir;// + vec3(0.,0.,zoffset);
  147. vec3 p3=(from+(s3+zoffset)*dir )* (1.9/zoom);// + vec3(0.,0.,zoffset);
  148.  
  149. p2 = abs(vec3(tile)-mod(p2,vec3(tile*3.5))); // tiling fold
  150. p3 = abs(vec3(tile)-mod(p3,vec3(tile*2.))); // tiling fold
  151.  
  152. #ifdef cloud
  153. t3 = field(p3);
  154. #endif
  155.  
  156. float pa,a=pa=0.;
  157. for (int i=0; i<iterations; i++) {
  158. p2=abs(p2)/dot(p2,p2)-formuparam; // the magic formula
  159. //p=abs(p)/max(dot(p,p),0.005)-formuparam; // another interesting way to reduce noise
  160. float D = abs(length(p2)-pa); // absolute sum of average change
  161.  
  162. if (i > 2)
  163. {
  164. a += i > 7 ? min( 12., D) : D;
  165. }
  166. pa=length(p2);
  167. }
  168.  
  169.  
  170. //float dm=max(0.,darkmatter-a*a*.001); //dark matter
  171. a*=a*a; // add contrast
  172. //if (r>3) fade*=1.-dm; // dark matter, don't render near
  173. // brightens stuff up a bit
  174. float s1 = s+zoffset;
  175. // need closed form expression for this, now that we shift samples
  176. float fade = pow(distfading,max(0.,float(r)-sampleShift));
  177.  
  178.  
  179. //t3 += fade;
  180.  
  181. v+=fade;
  182. //backCol2 -= fade;
  183.  
  184. // fade out samples as they approach the camera
  185. if( r == 0 )
  186. fade *= (1. - (sampleShift));
  187. // fade in samples as they approach from the distance
  188. if( r == volsteps-1 )
  189. fade *= sampleShift;
  190. v+=vec3(s1,s1*s1,s1*s1*s1*s1)*a*brightness*fade; // coloring based on distance
  191.  
  192. backCol2 += mix(.4, 1., v2) * vec3(0.20 * t3 * t3 * t3, 0.4 * t3 * t3, t3 * 0.7) * fade;
  193.  
  194.  
  195. s+=stepsize;
  196. s3 += stepsize;
  197.  
  198.  
  199.  
  200. }
  201.  
  202. v=mix(vec3(length(v)),v,saturation); //color adjust
  203.  
  204.  
  205.  
  206.  
  207. vec4 forCol2 = vec4(v*.01,1.);
  208.  
  209. #ifdef cloud
  210. backCol2 *= cloud;
  211. #endif
  212.  
  213. backCol2.b *= 0.01;
  214.  
  215. backCol2.r *= 0.01;
  216.  
  217.  
  218.  
  219. backCol2.b = 0.5*mix(backCol2.b, backCol2.g, 1.2);
  220. backCol2.g = 0.01;
  221.  
  222. backCol2.bg = mix(backCol2.gb, backCol2.bg, 0.5*(cos(time*0.01) + 1.0));
  223.  
  224. gl_FragColor = forCol2 + vec4(backCol2, 1.0);
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement